TypeBuilder.MakeArrayType Methode

Definition

Gibt ein Type-Objekt zurück, das ein Array des aktuellen Typs darstellt.

Überlädt

MakeArrayType(Int32)

Gibt ein Type-Objekt zurück, das ein Array vom aktuellen Typ mit der angegebenen Anzahl von Dimensionen darstellt.

MakeArrayType()

Gibt ein Type-Objekt zurück, das ein eindimensionales Array vom aktuellen Typ mit einer unteren Grenze von 0 (null) darstellt.

MakeArrayType(Int32)

Quelle:
TypeBuilder.cs
Quelle:
TypeBuilder.cs
Quelle:
TypeBuilder.cs

Gibt ein Type-Objekt zurück, das ein Array vom aktuellen Typ mit der angegebenen Anzahl von Dimensionen darstellt.

public:
 override Type ^ MakeArrayType(int rank);
public override Type MakeArrayType (int rank);
override this.MakeArrayType : int -> Type
Public Overrides Function MakeArrayType (rank As Integer) As Type

Parameter

rank
Int32

Die Anzahl von Dimensionen für das Array.

Gibt zurück

Ein Type-Objekt, das ein eindimensionales Array des aktuellen Typs darstellt.

Ausnahmen

rank ist keine gültige Arraydimension.

Beispiele

Im folgenden Codebeispiel werden ein dynamisches Modul, ein abstrakter Typ mit dem Namen Sampleund eine abstrakte Methode mit dem Namen TestMethoderstellt. TestMethodnimmt einen ref Parameter (ByRef in Visual Basic) vom Typ Sample, einen Zeiger auf den Typ Sampleund ein Array vom Typ .Sample Es gibt ein zweidimensionales Array vom Typ Samplezurück. Im Codebeispiel wird das dynamische Modul auf dem Datenträger gespeichert, sodass Sie es mit dem Ildasm.exe (IL Disassembler) untersuchen können.

using System;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.VisualBasic;

public class Example
{
    public static void Main()
    {
        // Define a dynamic assembly to contain the sample type. The
        // assembly will not be run, but only saved to disk, so
        // AssemblyBuilderAccess.Save is specified.
        //
        AppDomain myDomain = AppDomain.CurrentDomain;
        AssemblyName myAsmName = new AssemblyName("MakeXxxTypeExample");
        AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
            myAsmName,
            AssemblyBuilderAccess.Save);

        // An assembly is made up of executable modules. For a single-
        // module assembly, the module name and file name are the same
        // as the assembly name.
        //
        ModuleBuilder myModule = myAssembly.DefineDynamicModule(
            myAsmName.Name,
            myAsmName.Name + ".dll");

        // Define the sample type.
        TypeBuilder myType = myModule.DefineType(
            "Sample",
            TypeAttributes.Public | TypeAttributes.Abstract);

        // Define a method that takes a ref argument of type Sample,
        // a pointer to type Sample, and an array of Sample objects. The
        // method returns a two-dimensional array of Sample objects.
        //
        // To create this method, you need Type objects that represent the
        // parameter types and the return type. Use the MakeByRefType,
        // MakePointerType, and MakeArrayType methods to create the Type
        // objects.
        //
        Type byRefMyType = myType.MakeByRefType();
        Type pointerMyType = myType.MakePointerType();
        Type arrayMyType = myType.MakeArrayType();
        Type twoDimArrayMyType = myType.MakeArrayType(2);

        // Create the array of parameter types.
        Type[] parameterTypes = {byRefMyType, pointerMyType, arrayMyType};

        // Define the abstract Test method. After you have compiled
        // and run this code example code, you can use ildasm.exe
        // to open MakeXxxTypeExample.dll, examine the Sample type,
        // and verify the parameter types and return type of the
        // TestMethod method.
        //
        MethodBuilder myMethodBuilder = myType.DefineMethod(
            "TestMethod",
            MethodAttributes.Abstract | MethodAttributes.Virtual
                | MethodAttributes.Public,
            twoDimArrayMyType,
            parameterTypes);

        // Create the type and save the assembly. For a single-file
        // assembly, there is only one module to store the manifest
        // information in.
        //
        myType.CreateType();
        myAssembly.Save(myAsmName.Name + ".dll");
    }
}
Imports System.Reflection
Imports System.Reflection.Emit

Public Class Example
    Public Shared Sub Main()
        ' Define a dynamic assembly to contain the sample type. The
        ' assembly will not be run, but only saved to disk, so
        ' AssemblyBuilderAccess.Save is specified.
        '
        Dim myDomain As AppDomain = AppDomain.CurrentDomain
        Dim myAsmName As New AssemblyName("MakeXxxTypeExample")
        Dim myAssembly As AssemblyBuilder = myDomain.DefineDynamicAssembly( _
            myAsmName, _
            AssemblyBuilderAccess.Save)

        ' An assembly is made up of executable modules. For a single-
        ' module assembly, the module name and file name are the same 
        ' as the assembly name. 
        '
        Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule( _
            myAsmName.Name, _
            myAsmName.Name & ".dll")

        ' Define the sample type.
        Dim myType As TypeBuilder = myModule.DefineType( _
            "Sample", _
            TypeAttributes.Public Or TypeAttributes.Abstract)

        ' Define a method that takes a ByRef argument of type Sample,
        ' a pointer to type Sample, and an array of Sample objects. The
        ' method returns a two-dimensional array of Sample objects.
        '
        ' To create this method, you need Type objects that represent the
        ' parameter types and the return type. Use the MakeByRefType, 
        ' MakePointerType, and MakeArrayType methods to create the Type
        ' objects.
        '
        Dim byRefMyType As Type = myType.MakeByRefType
        Dim pointerMyType As Type = myType.MakePointerType
        Dim arrayMyType As Type = myType.MakeArrayType
        Dim twoDimArrayMyType As Type = myType.MakeArrayType(2)

        ' Create the array of parameter types.
        Dim parameterTypes() As Type = _
            {byRefMyType, pointerMyType, arrayMyType}

        ' Define the abstract Test method. After you have compiled
        ' and run this code example code, you can use ildasm.exe 
        ' to open MakeXxxTypeExample.dll, examine the Sample type,
        ' and verify the parameter types and return type of the
        ' TestMethod method.
        '
        Dim myMethodBuilder As MethodBuilder = myType.DefineMethod( _
            "TestMethod", _
            MethodAttributes.Abstract Or MethodAttributes.Virtual _
                Or MethodAttributes.Public, _
            twoDimArrayMyType, _
            parameterTypes)

        ' Create the type and save the assembly. For a single-file 
        ' assembly, there is only one module to store the manifest 
        ' information in.
        '
        myType.CreateType()
        myAssembly.Save(myAsmName.Name & ".dll")

    End Sub
End Class

Hinweise

Die MakeArrayType -Methode bietet eine Möglichkeit, einen Arraytyp mit jedem möglichen Elementtyp zu generieren, einschließlich generischer Typen.

Weitere Informationen

Gilt für:

MakeArrayType()

Quelle:
TypeBuilder.cs
Quelle:
TypeBuilder.cs
Quelle:
TypeBuilder.cs

Gibt ein Type-Objekt zurück, das ein eindimensionales Array vom aktuellen Typ mit einer unteren Grenze von 0 (null) darstellt.

public:
 override Type ^ MakeArrayType();
public override Type MakeArrayType ();
override this.MakeArrayType : unit -> Type
Public Overrides Function MakeArrayType () As Type

Gibt zurück

Ein Type-Objekt, das einen eindimensionalen Arraytyp, dessen Elementtyp dem aktuellen Typ entspricht, mit einer unteren Grenze von 0 (null) darstellt.

Beispiele

Im folgenden Codebeispiel werden ein dynamisches Modul, ein abstrakter Typ mit dem Namen Sampleund eine abstrakte Methode mit dem Namen TestMethoderstellt. TestMethodnimmt einen ref Parameter (ByRef in Visual Basic) vom Typ Sample, einen Zeiger auf den Typ Sampleund ein Array vom Typ .Sample Es gibt ein zweidimensionales Array vom Typ Samplezurück. Im Codebeispiel wird das dynamische Modul auf dem Datenträger gespeichert, sodass Sie es mit dem Ildasm.exe (IL Disassembler) untersuchen können.

using System;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.VisualBasic;

public class Example
{
    public static void Main()
    {
        // Define a dynamic assembly to contain the sample type. The
        // assembly will not be run, but only saved to disk, so
        // AssemblyBuilderAccess.Save is specified.
        //
        AppDomain myDomain = AppDomain.CurrentDomain;
        AssemblyName myAsmName = new AssemblyName("MakeXxxTypeExample");
        AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
            myAsmName,
            AssemblyBuilderAccess.Save);

        // An assembly is made up of executable modules. For a single-
        // module assembly, the module name and file name are the same
        // as the assembly name.
        //
        ModuleBuilder myModule = myAssembly.DefineDynamicModule(
            myAsmName.Name,
            myAsmName.Name + ".dll");

        // Define the sample type.
        TypeBuilder myType = myModule.DefineType(
            "Sample",
            TypeAttributes.Public | TypeAttributes.Abstract);

        // Define a method that takes a ref argument of type Sample,
        // a pointer to type Sample, and an array of Sample objects. The
        // method returns a two-dimensional array of Sample objects.
        //
        // To create this method, you need Type objects that represent the
        // parameter types and the return type. Use the MakeByRefType,
        // MakePointerType, and MakeArrayType methods to create the Type
        // objects.
        //
        Type byRefMyType = myType.MakeByRefType();
        Type pointerMyType = myType.MakePointerType();
        Type arrayMyType = myType.MakeArrayType();
        Type twoDimArrayMyType = myType.MakeArrayType(2);

        // Create the array of parameter types.
        Type[] parameterTypes = {byRefMyType, pointerMyType, arrayMyType};

        // Define the abstract Test method. After you have compiled
        // and run this code example code, you can use ildasm.exe
        // to open MakeXxxTypeExample.dll, examine the Sample type,
        // and verify the parameter types and return type of the
        // TestMethod method.
        //
        MethodBuilder myMethodBuilder = myType.DefineMethod(
            "TestMethod",
            MethodAttributes.Abstract | MethodAttributes.Virtual
                | MethodAttributes.Public,
            twoDimArrayMyType,
            parameterTypes);

        // Create the type and save the assembly. For a single-file
        // assembly, there is only one module to store the manifest
        // information in.
        //
        myType.CreateType();
        myAssembly.Save(myAsmName.Name + ".dll");
    }
}
Imports System.Reflection
Imports System.Reflection.Emit

Public Class Example
    Public Shared Sub Main()
        ' Define a dynamic assembly to contain the sample type. The
        ' assembly will not be run, but only saved to disk, so
        ' AssemblyBuilderAccess.Save is specified.
        '
        Dim myDomain As AppDomain = AppDomain.CurrentDomain
        Dim myAsmName As New AssemblyName("MakeXxxTypeExample")
        Dim myAssembly As AssemblyBuilder = myDomain.DefineDynamicAssembly( _
            myAsmName, _
            AssemblyBuilderAccess.Save)

        ' An assembly is made up of executable modules. For a single-
        ' module assembly, the module name and file name are the same 
        ' as the assembly name. 
        '
        Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule( _
            myAsmName.Name, _
            myAsmName.Name & ".dll")

        ' Define the sample type.
        Dim myType As TypeBuilder = myModule.DefineType( _
            "Sample", _
            TypeAttributes.Public Or TypeAttributes.Abstract)

        ' Define a method that takes a ByRef argument of type Sample,
        ' a pointer to type Sample, and an array of Sample objects. The
        ' method returns a two-dimensional array of Sample objects.
        '
        ' To create this method, you need Type objects that represent the
        ' parameter types and the return type. Use the MakeByRefType, 
        ' MakePointerType, and MakeArrayType methods to create the Type
        ' objects.
        '
        Dim byRefMyType As Type = myType.MakeByRefType
        Dim pointerMyType As Type = myType.MakePointerType
        Dim arrayMyType As Type = myType.MakeArrayType
        Dim twoDimArrayMyType As Type = myType.MakeArrayType(2)

        ' Create the array of parameter types.
        Dim parameterTypes() As Type = _
            {byRefMyType, pointerMyType, arrayMyType}

        ' Define the abstract Test method. After you have compiled
        ' and run this code example code, you can use ildasm.exe 
        ' to open MakeXxxTypeExample.dll, examine the Sample type,
        ' and verify the parameter types and return type of the
        ' TestMethod method.
        '
        Dim myMethodBuilder As MethodBuilder = myType.DefineMethod( _
            "TestMethod", _
            MethodAttributes.Abstract Or MethodAttributes.Virtual _
                Or MethodAttributes.Public, _
            twoDimArrayMyType, _
            parameterTypes)

        ' Create the type and save the assembly. For a single-file 
        ' assembly, there is only one module to store the manifest 
        ' information in.
        '
        myType.CreateType()
        myAssembly.Save(myAsmName.Name & ".dll")

    End Sub
End Class

Hinweise

Die MakeArrayType -Methode bietet eine Möglichkeit, einen Arraytyp mit jedem möglichen Elementtyp zu generieren, einschließlich generischer Typen.

Weitere Informationen

Gilt für: