C# 4.0: Dynamic, Inheriting from DynamicObject
问题 Let's say I have this: dynamic foo = new Foobar(); And I have this: public class Foobar : DynamicObject { } The question is, is it possible to override members of DynamicObject so that this code: string name = new Foobar().Name Does not throw an Exception at run-time? I want to return default for name 's if Name is not a member. Possible? What do I need to override? 回答1: Override TryGetMember (and TrySetMember). Classes derived from the DynamicObject class can override this method to specify