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

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

Property Prop(ByVal type As SomeEnum) As Currency

This is how I instantiate the object:

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

I tried the vb6 syntax in C #, but it doesn’t work (not even compiling):

obj.Prop(enumValue) = 1.2m;

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

Edit:

This method does not work with dynamic. AFAIK works with COM Interop:

obj.get_Prop(enumValue);
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 also works:

obj.Prop[enumValue] = 1.2m;
+3
source share
2 answers

C # property pointers are written as arrays.

obj.Prop[enumValue] = 1.2m;
+3
source

I am not 100% sure about this, but I believe that the properties in VB6 COM objects are actually translated into methods in C #.

, Get obj.get_Prop(); obj.set_Prop (newValue);

0

All Articles