I have a method like this,
public List<T> Test<T>()
{
// do something.
}
I don’t know what is T and dont have. But I have type of T as TYPE.
for example:
class Person
{
}
var type = typeof(Person);
I don’t have Person. Person is keeping at the type object.
How can I use the test method ?
var list = Test<type>(); // It gives an error like this. I must use the type object.
You can use the
MakeGenericMethodmethod fromMethodInfo:This is assuming you call the method inside the same type that defines
Test. If you call it from somewhere else, usetypeof(ClassThatDefinesTest)instead ofthis.GetType(), and the instance of this class instead ofthis.