我有两个静态类,一个嵌套在另一个中,如下所示:
public static class ClassA
{
private static class ClassB
{
...
}
}
我想使用反射获取ClassB的System.Type对象。如果没有反思,它将像这样简单:
Type t = typeof(ClassB);
但是,必须在编译应用程序后确定此类型。这是我到目前为止的内容:
// in this case I know that there is exactly one ClassB
// so for simplicity's sake I have referenced the first element within the array
// the member info struct is filled correctly with information about ClassB.
System.Reflection.MemberInfo memberInfo = typeof(ClassA).GetMember("ClassB",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)[0];
// the type returned here does not reflect ClassB
Type t = memberInfo.GetType();
你MemberInfo
是班上的。只需将其投放到Type
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句