Dynamic Parameters With Reflection

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

I have the following code:

Me.GetType().InvokeMember(FunctionToRun, BindingFlags.InvokeMethod, Nothing, Me, params)

I can send in a string from a database into the FunctionToRun variable, and it will run the method in the current class, but I need to read parameters from a database into the params object, and this is where I am stuck. It seems that the params may need to be actual variables, but I am not sure. How can I take a list of params that are located in a database (basically, just a string) and use this in the params for the reflection call?

Derek
 
Hi Derek,
How can I take a list of params that are
located in a database (basically, just a string) and use this in the params for
the reflection call?

InvokeMember takes an object[], and those objects must be convertible to the parameter type. So you will need to convert your string values into arguments. The Convert class is your friend for built in types. If you have User Defined Types consider writing a TypeConverter for them and using TypeDescriptor or explicit reflection calls to obtain the TypeConverter to do the conversion with. Alternatively you could implement IConvertible.
HTH,
Ian Cooper
wwww.dnug.org.uk
 
Back
Top