Tuesday, January 28, 2014

C# use a Type in a generic method definition

To use a Type within a generic method initialization, it can be accomplished with:


MethodInfo method = typeof(NameOfClass).GetMethod("MethodName", BindingFlags.Public | BindingFlags.Static);

method = method.MakeGenericMethod(type);
 
string results = (string)method.Invoke(null, new object[] { props[key] });

No comments: