我有一個靜態方法的類:調用靜態方法給它在C#動態類型和參數
public class MyClass {
public static bool MyMethod<T>(string arg1) where T : class {
// ...
}
}
我如何可以調用因爲我知道我的類型T
應該MyNamespace.Data.Models.Student
(這是通過變量提供),arg1
的值可以說是student
。
它與以下內容類似嗎?我不知道如何爲它設置T
類型。
Type.GetType("MyClass").GetMethod("MyMethod").Invoke(null, new object[] { arg1 = "student" })
可能重複http://stackoverflow.com/ questions/232535/how-to-use-reflection-to-call-generic-method –