Passing dynamic arguments breaks current interfaces

I have a set of so-called free interfaces, so I can use the syntax as follows:

.

a.With ("ABC") Do ("this") Then ("what).

Each method returns an object converted to the corresponding interface. During development, I can use Intellisense to easily navigate between API methods. However, I can no longer do this if I applied one of the arguments to the dynamic:

a.With ((dynamic) "ABC") Do ("this") Then ("what) ..

Not only do I lose Intellisense during development, this effect affects execution at runtime: all subsequent calls after With return objects of a dynamic type, potentially breaking the execution logic.

I do not understand why a dynamic argument should affect contracts that use only static types. If the With method is designed to return an ISomeInterface instance, and the implementation returns SomeClass (which implements ISomeInterface), why does the dynamic object used in an unconnected place infect the entire subsequent call chain? Is there any way to prevent this?

+1
source share
1 answer

I believe this post by Eric Lippert answers everything:

http://blogs.msdn.com/b/ericlippert/archive/2012/10/22/a-method-group-of-one.aspx

0
source

All Articles