, , ( #), , TryInvokeMember ( ). , :
class Test : DynamicObject {
public void Foo() {
Console.WriteLine("Foo called");
}
protected void Bar() {
Console.WriteLine("Bar called");
}
public override bool TryInvokeMember
(InvokeMemberBinder binder, object[] args, out object result) {
Console.WriteLine("Calling: " + binder.Name);
return base.TryInvokeMember(binder, args, out result);
}
}
:
dynamic d = new Test();
d.Foo(); // this will call 'Foo' directly (without calling 'TryInvokeMember')
d.Bar(); // this will call 'TryInvokeMember' and then throw exception
, base TryInvokeMember, # , TryInvokeMember ( result true).