all groups > dotnet windows forms > august 2003 >
You're in the

dotnet windows forms

group:

Dynamic Parameters With Reflection



Dynamic Parameters With Reflection Derek Hart
8/4/2003 11:45:49 PM
dotnet windows forms: 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?

Re: Dynamic Parameters With Reflection Ian Cooper
8/5/2003 9:12:56 AM
Hi Derek,
[quoted text, click to view]

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
AddThis Social Bookmark Button