COMBinder, Default property and indexed property

Aug 4, 2009 at 8:57 PM

I wonder whether DLR Combinder would take care default property and indexed property or that is the job of language implementation.

For example, o[i] could mean just o[i] or o.DefaultProperty[i]. In a scripting language, both of these scenarious have the same semantic as [Get|Set]IndexBinder.

Similarly, o.Something[i] could mean o has an index property, or o has a property "Something" that returns an object that has index, or o has a property that returns an object that has default property. In a scripting language, all these have the same semantics as the InvokeMemberBinder, but a language implementation would have to reflect on the object at runtime to generate the correct binding if it is not automatically taken care by the COMBinder.

Without diving into the code of COMBinder or using reflector on code generated by C# 4.0, can anybody give me a quick answer? Thanks.

Li

Aug 4, 2009 at 9:42 PM

> I wonder whether DLR Combinder would take care default property and indexed property or that is the job of language implementation.

Yup, ComBinder will take care of it—it’s intended to work just like VBA and VB.NET late bound, so behavior should be pretty much what you’d expect. Default properties will work using either GetIndex or Invoke on the COM object. Indexed properties work using either GetMember followed by GetIndex/Invoke, or just an InvokeMember on the COM object.

- John

Aug 4, 2009 at 9:51 PM
It is great to know. Thanks!

Aug 5, 2009 at 5:24 AM

I have another question regarding default property. In VBA, if I have:

Set c = Grid.Cell

c would contains a Cell object. However, if I write:

v = Grid.Cell

v would contains the value of the default property of Cell object.

I think it is fairly easy to write a DLR tree to get the Cell object with GetMemberBinder. Is is possible to have COMBinder bind to the default value in the second case without actually using reflection to get the name of the default property?