It's been concerning me that the duck-typing libraries I can find for C# all breaks object identity, ie Object.ReferenceEquals
returns false for a duck-typed object and its original object.
It seems impossible to achieve a wrapper/proxy-less solution in C#, esp. given that it's a fundamental OO concept, but hoping I'm wrong, anyone know if there is a way, especially in later language versions?
Edit, a code example was requested:
public class MyClass
{
private SomeInterface _someInterface;
// Dynamic is possible here but the type safety is helpful
// when having multiple constructors, for example.
public MyClass(AnotherClass c)
{
_someInterface = c.ActLike<SomeInterface>();
Trace.Assert(object.ReferenceEquals(c, _someInterface));
}
}