的我有,我想獲取類型名出的類層次:全名通用基類型
class Alice
:ThirdPersonCharacter<Foo, Bar>
class ThirdPersonCharacter<A, B>
:BaseHumanoidCharacter<A, B>, ISomeInterface
where A : Something
class BaseHumanoidCharacter<A, B>
: Entity,
ISomeOtherInterface
where A : Something
我想所有的基本類型愛麗絲的,所以我這樣做:
private static IEnumerable<Type> BaseTypes(Type t)
{
while (t.BaseType != null)
{
yield return t.BaseType;
t = t.BaseType;
}
}
var aliceTypes = baseTypes(typeof(Alice)).Select(a => a.AssemblyQualifiedName).ToArray();
問題是這樣的是找到BaseHumanoidCharacter類型是:
{Name = "BaseHumanoidCharacter`2" FullName = null}
當然
我真正想要的是:
{Name = "BaseHumanoidCharacter`2[[X.Y.Z.Foo, AssemblyName, version=123, Culture=whatever, PublicKey=stuff],[X.Y.Z.Bar, AssemblyName, version=123, Culture=whatever, PublicKey=stuff]]", FullName = "Something that isn't null"}
有沒有辦法修改這個系統給我有用的類型與他們的通用參數填寫,他們的FullName不爲空?
爲了全面瞭解您的類層次結構會有所幫助,如果您還顯示,愛麗絲源自Character類 - 或者是一個錯字? – Markus
是的,對不起。我的意思是更具體的ThirdPersonCharacter。 – Martin