Edit

Share via


Assembly.GetExportedTypes Method

Definition

Gets the public types defined in this assembly that are visible outside the assembly.

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

Returns

Type[]

An array that represents the types defined in this assembly that are visible outside the assembly.

Implements

Exceptions

The assembly is a dynamic assembly.

Unable to load a dependent assembly.

Examples

The following code sample defines a number of classes with various access levels, and calls GetExportedTypes to display the ones that are visible from outside the assembly.

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

Remarks

The only types visible outside an assembly are public types and public types nested within other public types. To retrieve all types within an assembly, including those that are non-public, use the GetTypes method.

Applies to