How to get and set a vb6 property with a parameter from c #?


I need to get and set a property with parameter from a vb6 object:

Property Prop(ByVal type As SomeEnum) As Currency

This is how I create an instance of the object:

dynamic obj = Activator.CreateInstance(Type.GetTypeFromProgID(progID));

I tried the vb6 syntax in c#, but it doesn't work (doesn't even compile):

obj.Prop(enumValue) = 1.2m;

So the question is: How to get and set a vb6 property with parameter from c#?


This method doesn't work with dynamic. AFAIK it works with COM Interop:

obj.set_Prop(enumValue, newValue);

The reflection approach works fine, but it is too verbose:

obj.GetType().InvokeMember("Prop", System.Reflection.BindingFlags.Public |
    System.Reflection.BindingFlags.SetProperty, null, obj,
    new object[] { enumValue, 1.2m });

The property indexer approach works too:

obj.Prop[enumValue] = 1.2m;

In C# property indexers are writen like arrays.

obj.Prop[enumValue] = 1.2m;