views:

57

answers:

2

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,
    Object[] 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?

A: 

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

Thomas Levesque
That is what I am thinking as well, but I just find it odd that nobody seems to mention it. I have found a few sources that claim result is used to signal if the binding succeeded or not. However, that is what the bool return type is for.
Brian Rasmussen
+3  A: 

Yes, just use null in this case.

There were some similar questions here before: http://stackoverflow.com/questions/1835912/how-do-i-express-a-void-method-call-as-the-result-of-dynamicmetaobject-bindinvoke 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.

Alexandra Rusina