Assembly.GetExportedTypes 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此程序集中定义的公共类型,这些公共类型在程序集外可见。
public:
virtual cli::array <Type ^> ^ GetExportedTypes();
public virtual Type[] GetExportedTypes ();
abstract member GetExportedTypes : unit -> Type[]
override this.GetExportedTypes : unit -> Type[]
Public Overridable Function GetExportedTypes () As Type()
返回
Type[]
一个数组,表示此程序集中定义并在程序集外可见的类型。
实现
例外
程序集是动态程序集。
无法加载从属程序集。
示例
下面的代码示例定义了具有各种访问级别的许多类,并调用 GetExportedTypes 以显示从程序集外部可见的类。
using namespace System;
using namespace System::Reflection;
namespace ExportedClassExample
{
public ref class Example sealed
{
private:
Example()
{
}
public:
void static EnumerateExportedTypes()
{
for each (Type^ exportedType in
Example::typeid->Assembly->GetExportedTypes())
{
Console::WriteLine(exportedType);
}
}
};
public ref class PublicClass
{
public:
ref class PublicNestedClass
{
};
protected:
ref class ProtectedNestedClass
{
};
internal:
ref class FriendNestedClass
{
};
private:
ref class PrivateNestedClass
{
};
};
ref class FriendClass
{
public:
ref class PublicNestedClass
{
};
protected:
ref class ProtectedNestedClass
{
};
internal:
ref class FriendNestedClass
{
};
private:
ref class PrivateNestedClass
{
};
};
}
int main()
{
ExportedClassExample::Example::EnumerateExportedTypes();
return 0;
}
using System;
using System.Reflection;
public class Example
{
public static void Main()
{
foreach (Type t in typeof(Example).Assembly.GetExportedTypes())
{
Console.WriteLine(t);
}
}
}
public class PublicClass
{
public class PublicNestedClass {}
protected class ProtectedNestedClass {}
internal class FriendNestedClass {}
private class PrivateNestedClass {}
}
internal class FriendClass
{
public class PublicNestedClass {}
protected class ProtectedNestedClass {}
internal class FriendNestedClass {}
private class PrivateNestedClass {}
}
Imports System.Reflection
Public Class Example
Public Shared Sub Main()
For Each t As Type In GetType(Example).Assembly.GetExportedTypes()
Console.WriteLine(t)
Next
End Sub
End Class
Public Class PublicClass
Public Class PublicNestedClass
End Class
Protected Class ProtectedNestedClass
End Class
Friend Class FriendNestedClass
End Class
Private Class PrivateNestedClass
End Class
End Class
Friend Class FriendClass
Public Class PublicNestedClass
End Class
Protected Class ProtectedNestedClass
End Class
Friend Class FriendNestedClass
End Class
Private Class PrivateNestedClass
End Class
End Class
注解
程序集外部唯一可见的类型是嵌套在其他公共类型中的公共类型和公共类型。 若要检索程序集中的所有类型(包括非公共类型),请使用 GetTypes 方法。