Apparently the following is valid in c# 4.0 regardless of the type of the object returned by GetADynamicThing()
dynamic d = GetADynamicThing();
d.Foo();
And if the runtime type of d does not contain a method Foo(), a RunTimeBinderException is thrown.
Will there be an easy way to determine if Foo() exists on d?
Otherwise, we're stuck doing old school reflection on the object, or relying on try-catch. Not sure I like either approach.
Update: So we have currently have 3 options:
- Reflection
- Catch Exception
- Hope GetADynamicThing() returns what you expect it to return
Number 3 seems to be the targeted usage of dynamic which in COM situations is great. The reason I asked the question originally was in response to doing something like this i.e. using methods some arbitrarily created object. This very much seems like the wrong situation to be using dynamic.