public override bool TryGetMember(GetMemberBinder binder, out object result) { if (members.ContainsKey(binder.Name)) { result = members[binder.Name]; } else { result = new NullExceptionPreventer(); } return(true); }
// all member access to a NullExceptionPreventer will return a new NullExceptionPreventer // this allows for infinite nesting levels: var s = Obj1.foo.bar.bla.blubb; is perfectly valid public override bool TryGetMember(GetMemberBinder binder, out object result) { result = new NullExceptionPreventer(); return(true); }