的我有,我想获取类型名出的类层次:全名通用基类型
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