B
brian
I have an application that dynamically invokes methods based on
information in an XML file. In order to do this, I first have to make
sure that a method with matching parameter types exists.
All of the usable methods have generic parameter types, but most of the
methods are not generic themselves, i.e.
public object MyMethod(Parameter<int> id, Parameter<string> name)
When the XML file is read, the data types are determined, and a Type
array of constructed generic types is formed. Just as example here this
code would basically do the same thing:
Type[] typeArray = new Type[] { typeof(Parameter<int>),
typeof(Parameter<string>) };
Then, I can successfully locate the method using
this.GetType().GetMethod(methodName, typeArray);
The problem I run across is when I create a generic method that has
generic parameter types of the same type as the method, such as:
public object MyGenericMethod<T>(Parameter<T> myParam)
Using the same GetMethod call as the one above, with the same Type
array, doesn't find any matching methods. So my question is, what
arguments would GetMethod() need in order to correctly locate this
method? Is there even a way to search for a particular form of a
generic method using GetMethod()?
Thanks in advance for any insight!
-Brian C. Stanford
information in an XML file. In order to do this, I first have to make
sure that a method with matching parameter types exists.
All of the usable methods have generic parameter types, but most of the
methods are not generic themselves, i.e.
public object MyMethod(Parameter<int> id, Parameter<string> name)
When the XML file is read, the data types are determined, and a Type
array of constructed generic types is formed. Just as example here this
code would basically do the same thing:
Type[] typeArray = new Type[] { typeof(Parameter<int>),
typeof(Parameter<string>) };
Then, I can successfully locate the method using
this.GetType().GetMethod(methodName, typeArray);
The problem I run across is when I create a generic method that has
generic parameter types of the same type as the method, such as:
public object MyGenericMethod<T>(Parameter<T> myParam)
Using the same GetMethod call as the one above, with the same Type
array, doesn't find any matching methods. So my question is, what
arguments would GetMethod() need in order to correctly locate this
method? Is there even a way to search for a particular form of a
generic method using GetMethod()?
Thanks in advance for any insight!
-Brian C. Stanford