Is it possible to intercept a method or property call to a dynamic variable?

I want to intercept calls to a dynamic type to avoid a RuntimeBinderException when the method or property called does not exist. For example:

class Foo { bool IsFool{ get; set; } } ... dynamic d = new Foo(); bool isFool = d.IsFoo; //works fine bool isSpecial = d.IsSpecial; //RuntimeBinderException 

What I want to do is to either create the nonexistent property when called or to just return null.

by This_Is_Drunk_Me via /r/csharp

Leave a Reply