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;
source
share