Partager via


GenericTypeParameterBuilder.MakeArrayType Méthode

Définition

Retourne le type d’un tableau dont le type d’élément est le paramètre de type générique.

Surcharges

MakeArrayType(Int32)

Retourne le type d’un tableau dont le type des éléments correspond au paramètre de type générique, avec le nombre spécifié de dimensions.

MakeArrayType()

Retourne le type d’un tableau unidimensionnel dont le type d’élément est le paramètre de type générique.

MakeArrayType(Int32)

Source:
GenericTypeParameterBuilder.cs

Retourne le type d’un tableau dont le type des éléments correspond au paramètre de type générique, avec le nombre spécifié de dimensions.

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

Paramètres

rank
Int32

Nombre de dimensions pour le tableau.

Retours

Objet Type qui représente le type d’un tableau dont le type des éléments correspond au paramètre de type générique, avec le nombre spécifié de dimensions.

Exceptions

rank n’est pas un nombre de dimensions valide. Par exemple, sa valeur est inférieure à 1.

Exemples

L’exemple de code suivant crée un module dynamique, un type générique abstrait nommé Sample avec un paramètre de type , Tet une méthode abstraite nommée TestMethod. TestMethod prend un ref paramètre (ByRef en Visual Basic) de type T, un pointeur vers le type Tet un tableau de T. Cette méthode retourne un tableau à deux dimensions de T. L’exemple de code enregistre le module dynamique sur le disque afin que vous puissiez l’examiner à l’aide du désassembleur MSIL (Ildasm.exe).

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;

int 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^ appDomain = AppDomain::CurrentDomain;
    AssemblyName^ assemblyName = gcnew
        AssemblyName("MakeXxxGenericTypeParameterExample");
    AssemblyBuilder^ assemblyBuilder = appDomain->DefineDynamicAssembly
        (assemblyName, 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^ moduleBuilder = assemblyBuilder->DefineDynamicModule
        (assemblyName->Name, assemblyName->Name + ".dll");

    // Define the sample type.
    TypeBuilder^ typeBuilder = moduleBuilder->DefineType("Sample",
        TypeAttributes::Public | TypeAttributes::Abstract);

    // Make the sample type a generic type, by defining a type
    // parameter T. All type parameters are defined at the same
    // time, by passing an array containing the type parameter
    // names. 
    array<String^>^ typeParamNames = {"T"};
    array<GenericTypeParameterBuilder^>^ typeParams =
        typeBuilder->DefineGenericParameters(typeParamNames);

    // Define a method that takes a ByRef argument of type T, a
    // pointer to type T, and one-dimensional array of type T.
    // The method returns a two-dimensional array of type T.
    //
    // To create this method, you need Type objects that repre-
    // sent the parameter types and the return type. Use the
    // MakeByRefType, MakePointerType, and MakeArrayType methods
    // to create the Type objects, using the generic type para-
    // meter T.
    //
    Type^ byRefType = typeParams[0]->MakeByRefType();
    Type^ pointerType = typeParams[0]->MakePointerType();
    Type^ arrayType = typeParams[0]->MakeArrayType();
    Type^ twoDimArrayType = typeParams[0]->MakeArrayType(2);

    // Create the array of parameter types.
    array<Type^>^ parameterTypes = {byRefType, pointerType, arrayType};

    // Define the abstract Test method. After you have compiled
    // and run this example code, you can use ildasm.exe to open
    // MakeXxxGenericTypeParameterExample.dll, examine the Sample
    // type, and verify the parameter types and return type of
    // the TestMethod method.
    //
    MethodBuilder^ methodBuilder = typeBuilder->DefineMethod("TestMethod",
        MethodAttributes::Abstract | MethodAttributes::Virtual 
        | MethodAttributes::Public, twoDimArrayType, parameterTypes);

    // Create the type and save the assembly. For a single-file 
    // assembly, there is only one module to store the manifest 
    // information in.
    //
    typeBuilder->CreateType();
    assemblyBuilder->Save(assemblyName->Name + ".dll");
};
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("MakeXxxGenericTypeParameterExample");
        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);

        // Make the sample type a generic type, by defining a type
        // parameter T. All type parameters are defined at the same
        // time, by passing an array containing the type parameter
        // names.
        string[] typeParamNames = {"T"};
        GenericTypeParameterBuilder[] typeParams =
            myType.DefineGenericParameters(typeParamNames);

        // Define a method that takes a ByRef argument of type T, a
        // pointer to type T, and one-dimensional array of type T. The
        // method returns a two-dimensional array of type T.
        //
        // 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, using the generic type parameter T.
        //
        Type byRefType = typeParams[0].MakeByRefType();
        Type pointerType = typeParams[0].MakePointerType();
        Type arrayType = typeParams[0].MakeArrayType();
        Type twoDimArrayType = typeParams[0].MakeArrayType(2);

        // Create the array of parameter types.
        Type[] parameterTypes = {byRefType, pointerType, arrayType};

        // Define the abstract Test method. After you have compiled
        // and run this example code, you can use ildasm.exe to open
        // MakeXxxGenericTypeParameterExample.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,
            twoDimArrayType,
            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("MakeXxxGenericTypeParameterExample")
        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)

        ' Make the sample type a generic type, by defining a type
        ' parameter T. All type parameters are defined at the same
        ' time, by passing an array containing the type parameter
        ' names. 
        Dim typeParamNames() As String = {"T"}
        Dim typeParams() As GenericTypeParameterBuilder = _
            myType.DefineGenericParameters(typeParamNames)

        ' Define a method that takes a ByRef argument of type T, a
        ' pointer to type T, and one-dimensional array of type T. The
        ' method returns a two-dimensional array of type T.
        '
        ' 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, using the generic type parameter T.
        '
        Dim byRefType As Type = typeParams(0).MakeByRefType
        Dim pointerType As Type = typeParams(0).MakePointerType
        Dim arrayType As Type = typeParams(0).MakeArrayType
        Dim twoDimArrayType As Type = typeParams(0).MakeArrayType(2)

        ' Create the array of parameter types.
        Dim parameterTypes() As Type = _
            {byRefType, pointerType, arrayType}

        ' Define the abstract Test method. After you have compiled
        ' and run this example code, you can use ildasm.exe to open
        ' MakeXxxGenericTypeParameterExample.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, _
            twoDimArrayType, _
            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

Remarques

La MakeArrayType méthode permet de générer des types de tableaux pour les listes de paramètres.

Voir aussi

S’applique à

MakeArrayType()

Source:
GenericTypeParameterBuilder.cs

Retourne le type d’un tableau unidimensionnel dont le type d’élément est le paramètre de type générique.

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

Retours

Objet Type qui représente le type d’un tableau unidimensionnel dont le type d’élément est le paramètre de type générique.

Exemples

L’exemple de code suivant crée un module dynamique, un type générique abstrait nommé Sample avec un paramètre de type , Tet une méthode abstraite nommée TestMethod. TestMethod prend un ref paramètre (ByRef en Visual Basic) de type T, un pointeur vers le type Tet un tableau de T. Cette méthode retourne un tableau à deux dimensions de T. L’exemple de code enregistre le module dynamique sur le disque afin que vous puissiez l’examiner à l’aide du désassembleur MSIL (Ildasm.exe).

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;

int 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^ appDomain = AppDomain::CurrentDomain;
    AssemblyName^ assemblyName = gcnew
        AssemblyName("MakeXxxGenericTypeParameterExample");
    AssemblyBuilder^ assemblyBuilder = appDomain->DefineDynamicAssembly
        (assemblyName, 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^ moduleBuilder = assemblyBuilder->DefineDynamicModule
        (assemblyName->Name, assemblyName->Name + ".dll");

    // Define the sample type.
    TypeBuilder^ typeBuilder = moduleBuilder->DefineType("Sample",
        TypeAttributes::Public | TypeAttributes::Abstract);

    // Make the sample type a generic type, by defining a type
    // parameter T. All type parameters are defined at the same
    // time, by passing an array containing the type parameter
    // names. 
    array<String^>^ typeParamNames = {"T"};
    array<GenericTypeParameterBuilder^>^ typeParams =
        typeBuilder->DefineGenericParameters(typeParamNames);

    // Define a method that takes a ByRef argument of type T, a
    // pointer to type T, and one-dimensional array of type T.
    // The method returns a two-dimensional array of type T.
    //
    // To create this method, you need Type objects that repre-
    // sent the parameter types and the return type. Use the
    // MakeByRefType, MakePointerType, and MakeArrayType methods
    // to create the Type objects, using the generic type para-
    // meter T.
    //
    Type^ byRefType = typeParams[0]->MakeByRefType();
    Type^ pointerType = typeParams[0]->MakePointerType();
    Type^ arrayType = typeParams[0]->MakeArrayType();
    Type^ twoDimArrayType = typeParams[0]->MakeArrayType(2);

    // Create the array of parameter types.
    array<Type^>^ parameterTypes = {byRefType, pointerType, arrayType};

    // Define the abstract Test method. After you have compiled
    // and run this example code, you can use ildasm.exe to open
    // MakeXxxGenericTypeParameterExample.dll, examine the Sample
    // type, and verify the parameter types and return type of
    // the TestMethod method.
    //
    MethodBuilder^ methodBuilder = typeBuilder->DefineMethod("TestMethod",
        MethodAttributes::Abstract | MethodAttributes::Virtual 
        | MethodAttributes::Public, twoDimArrayType, parameterTypes);

    // Create the type and save the assembly. For a single-file 
    // assembly, there is only one module to store the manifest 
    // information in.
    //
    typeBuilder->CreateType();
    assemblyBuilder->Save(assemblyName->Name + ".dll");
};
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("MakeXxxGenericTypeParameterExample");
        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);

        // Make the sample type a generic type, by defining a type
        // parameter T. All type parameters are defined at the same
        // time, by passing an array containing the type parameter
        // names.
        string[] typeParamNames = {"T"};
        GenericTypeParameterBuilder[] typeParams =
            myType.DefineGenericParameters(typeParamNames);

        // Define a method that takes a ByRef argument of type T, a
        // pointer to type T, and one-dimensional array of type T. The
        // method returns a two-dimensional array of type T.
        //
        // 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, using the generic type parameter T.
        //
        Type byRefType = typeParams[0].MakeByRefType();
        Type pointerType = typeParams[0].MakePointerType();
        Type arrayType = typeParams[0].MakeArrayType();
        Type twoDimArrayType = typeParams[0].MakeArrayType(2);

        // Create the array of parameter types.
        Type[] parameterTypes = {byRefType, pointerType, arrayType};

        // Define the abstract Test method. After you have compiled
        // and run this example code, you can use ildasm.exe to open
        // MakeXxxGenericTypeParameterExample.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,
            twoDimArrayType,
            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("MakeXxxGenericTypeParameterExample")
        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)

        ' Make the sample type a generic type, by defining a type
        ' parameter T. All type parameters are defined at the same
        ' time, by passing an array containing the type parameter
        ' names. 
        Dim typeParamNames() As String = {"T"}
        Dim typeParams() As GenericTypeParameterBuilder = _
            myType.DefineGenericParameters(typeParamNames)

        ' Define a method that takes a ByRef argument of type T, a
        ' pointer to type T, and one-dimensional array of type T. The
        ' method returns a two-dimensional array of type T.
        '
        ' 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, using the generic type parameter T.
        '
        Dim byRefType As Type = typeParams(0).MakeByRefType
        Dim pointerType As Type = typeParams(0).MakePointerType
        Dim arrayType As Type = typeParams(0).MakeArrayType
        Dim twoDimArrayType As Type = typeParams(0).MakeArrayType(2)

        ' Create the array of parameter types.
        Dim parameterTypes() As Type = _
            {byRefType, pointerType, arrayType}

        ' Define the abstract Test method. After you have compiled
        ' and run this example code, you can use ildasm.exe to open
        ' MakeXxxGenericTypeParameterExample.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, _
            twoDimArrayType, _
            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

Remarques

La MakeArrayType méthode permet de générer des types de tableaux pour les listes de paramètres.

Voir aussi

S’applique à