The value of the result when implementing invalid methods through DynamicObject

I am looking at examples of overriding TryInvokeMemberon DynamicObjectto implement dynamic method bindings. The signature is as follows

public virtual bool TryInvokeMember(
    InvokeMemberBinder binder,
    Object[] args,
    out Object result
)

Obviously, it is resultused to pass the result back to the caller.

Since there is no overload for TryInvokeMemberwithout an resultout parameter , I assume that this method should also handle invalid methods. In this case, are there any recommendations as to what should be installed result?

The default implementation does not DynamicObjectset resultto null, and this will also be my default choice, but I could not find mention of this in the examples. Are there any recommendations for this? No matter what the result?

+3
source share
2 answers

Yes, just use null in this case.

Here were some similar questions: How to express a void method call as a result of DynamicMetaObject.BindInvokeMember? This is one of IDynamicMetaObjectProvider, but DynamicObject is just one of its implementations. In short, DLR will always return something, this does not allow returning a void.

, MSDN. DynamicObject.TryInvokeMember.

+4

, , ...

0

Source: https://habr.com/ru/post/1736298/


All Articles