Assembly.GetExportedTypes Metoda

Definicja

Pobiera typy publiczne zdefiniowane w tym zestawie, które są widoczne poza zestawem.

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()

Zwraca

Type[]

Tablica reprezentująca typy zdefiniowane w tym zestawie, które są widoczne poza zestawem.

Implementuje

Wyjątki

Zestaw jest zestawem dynamicznym.

Nie można załadować zestawu zależnego.

Przykłady

Poniższy przykładowy kod definiuje wiele klas z różnymi poziomami dostępu i wywołania GetExportedTypes , aby wyświetlić te, które są widoczne spoza zestawu.

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

Uwagi

Jedynymi typami widocznymi poza zestawem są typy publiczne i typy publiczne zagnieżdżone w innych typach publicznych. Aby pobrać wszystkie typy w zestawie, w tym te, które nie są publiczne, użyj GetTypes metody .

Dotyczy