C# 如何使用反射获取系统类型的静态成员?

C# 如何使用反射获取系统类型的静态成员?,c#,reflection,C#,Reflection,我有两个静态类,一个嵌套在另一个中,如下所示: public static class ClassA { private static class ClassB { ... } } 我想使用反射得到类B的System.Type对象。如果没有思考,它将是如此简单: Type t = typeof(ClassB); 但是,有必要在编译应用程序后确定此类型。以下是我到目前为止的情况: // in this case I know that there is

我有两个静态类,一个嵌套在另一个中,如下所示:

public static class ClassA
{
    private static class ClassB
    {
        ...
    }
}
我想使用反射得到类B的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
就是这个类。只需将其转换为
类型