tobias233
New member
- Joined
- Nov 12, 2015
- Messages
- 1
- Programming Experience
- 5-10
Hello :joyous:,
I am doing C# for a half year now. Today I want to call a method like this in a class with the name "A":
At compile time, T isn't known.
So I tried the following:
The code above is okay for execute the method in these form:
But now I want to execute the method so:
How can I handle this? Thanks for help!
I am doing C# for a half year now. Today I want to call a method like this in a class with the name "A":
C#:
public T TheMethod<T>(IRestResponse response) {
...
}
At compile time, T isn't known.
C#:
var theType = typeof(B);
So I tried the following:
C#:
var gMethod= typeof(A).GetMethod("TheMethod");
var rExecution = gMethod.MakeGenericMethod(theType);
var params = ...;
var result = (C)rExecution.Invoke(new A(), new object[] { params });
The code above is okay for execute the method in these form:
C#:
public C TheMethod<T>(IRestResponse response) {
...
}
But now I want to execute the method so:
C#:
public List<T> TheMethod<T>(IRestResponse response) {
...
}
How can I handle this? Thanks for help!