我有一個泛型類,如下圖所示:C# - 如何在運行時GetType的類與泛型參數?
using System.Collections.Generic;
namespace MyNameSpace
{
public class MyClass<T> : MyAnotherClass
{
public MyClass();
public MyClass(T obj);
public T Object { get; set; }
}
}
我不明白,爲什麼下面的代碼返回空行(throwing exception with message : "Could not load type 'MyClass' from assembly '//assembly details//' "
)
Type MyClassType = AssemblyContaingMyClass.GetType("MyNameSpace.MyClass");
是否非法使用Assembly.GetType( className)與泛型類?
你可以建議任何其他方法在運行時獲取泛型類型嗎?
在此先感謝和道歉,如果這個問題太基本。我是c#的新手。
編輯:
忘了提。包含MyClass的程序集將被加載運行時。
嘗試'MyNameSpace.MyClass <>' – sll
我做過。也試過MyNameSpace.MyClass –