共用方式為


Assembly.GetExportedTypes 方法

定義

取得在這個組件中定義的公用類型,而這些類型在組件外部是可見的。

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 方法。

適用於