Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C# reflection invoke static generic method

//If we want to call the GenericMethod with type string.
var sample = new Sample(); //or you can get an instance via reflection
var method = typeof(Sample).GetMethod("GenericMethod");
var generic = method.MakeGenericMethod(typeof(string));
generic.Invoke(sample, null);//Since there are no arguments, we are passing null

//For the static method you do not need an instance. Therefore the first argument will also be null.
var method = typeof(Sample).GetMethod("StaticMethod");
var generic = method.MakeGenericMethod(typeof(string));
generic.Invoke(null, null);
 
PREVIOUS NEXT
Tagged: #reflection #invoke #static #generic #method
ADD COMMENT
Topic
Name
6+6 =