开发者

Value of result when implementing void methods via DynamicObject

I'm looking at the examples for overriding TryInvokeMember on DynamicObject to implement dynamic method binding. The signature is as follows

public virtual bool TryInvokeMember(
    InvokeMemberBinder binder,
    Objec开发者_StackOverflowt[] args,
    out Object result
)

Obviously result is used to pass the result back to the caller.

Since there is no overload for TryInvokeMember without the result out parameter, I assume this method must handle void methods as well. In that case are there any guidelines for what result should be set to?

The default implementation on DynamicObject sets result to null, and that would be my default choice as well, but I haven't been able to find any mention of this in the examples. Are there any guidelines for this? Does it even matter what the result is?


Yes, just use null in this case.

There were some similar questions here before: How do I express a void method call as the result of DynamicMetaObject.BindInvokeMember? This one is about IDynamicMetaObjectProvider, but DynamicObject is just one of its implementations. Shortly, DLR will always return something, it doesn't allow returning void.

I'll see what I can do about MSDN docs. I may add a note about this to the DynamicObject.TryInvokeMember.


I think it doesn't matter, since the result will be ignored anyway...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜