Language: C#
Dynamic - Abuse or Win?
// la la la if (foo is ISomeInterface) { ((ISomeInterface)foo).SomeMethod(); } else if (foo is ISomeOtherInterface) { ((ISomeOtherInterface)foo).SomeMethod(); } else { throw new SomeException(); } // or, just abuse dynamic! :) ((dynamic)foo).SomeMethod();
Tags:
by Rick Strahl
August 11, 2010 @ 5:27pm
Depends on the scenario. If you know what interfaces/types you're expecting you should always try to use them. Dynamic is perfect if you truly don't know and you can justify of the overhead of dynamic.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search


I call that a perfect use of dynamic.