英語で読む

次の方法で共有


TypeBuilder.MakeArrayType メソッド

定義

現在の型の配列を表す Type オブジェクトを返します。

オーバーロード

MakeArrayType(Int32)

次元数を指定して現在の型の配列を表す Type オブジェクトを返します。

MakeArrayType()

下限を 0 に設定して現在の型の 1 次元配列を表す Type オブジェクトを返します。

MakeArrayType(Int32)

ソース:
TypeBuilder.cs
ソース:
TypeBuilder.cs
ソース:
TypeBuilder.cs

次元数を指定して現在の型の配列を表す Type オブジェクトを返します。

C#
public override Type MakeArrayType(int rank);

パラメーター

rank
Int32

配列の次元数。

戻り値

現在の型の 1 次元配列を表す Type オブジェクト。

例外

rank は有効な配列の次元ではありません。

次のコード例では、動的モジュール、という名前の抽象型、および というSampleTestMethod名前の抽象メソッドを作成します。 TestMethodは、 型のrefパラメーター (ByRef Visual Basic では )、型Sampleへのポインター、および 型SampleSampleの配列を受け取ります。 型 Sampleの 2 次元配列を返します。 このコード例では、動的モジュールをディスクに保存するため、 Ildasm.exe (IL 逆アセンブラー) を使用して調べることができます。

C#
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");
    }
}

注釈

メソッドは MakeArrayType 、ジェネリック型を含む任意の要素型を使用して配列型を生成する方法を提供します。

こちらもご覧ください

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1

MakeArrayType()

ソース:
TypeBuilder.cs
ソース:
TypeBuilder.cs
ソース:
TypeBuilder.cs

下限を 0 に設定して現在の型の 1 次元配列を表す Type オブジェクトを返します。

C#
public override Type MakeArrayType();

戻り値

下限を 0 に設定して要素型が現在の型である 1 次元配列を表す Type オブジェクト。

次のコード例では、動的モジュール、という名前の抽象型、および というSampleTestMethod名前の抽象メソッドを作成します。 TestMethodは、 型のrefパラメーター (ByRef Visual Basic では )、型Sampleへのポインター、および 型SampleSampleの配列を受け取ります。 型 Sampleの 2 次元配列を返します。 このコード例では、動的モジュールをディスクに保存するため、 Ildasm.exe (IL 逆アセンブラー) を使用して調べることができます。

C#
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");
    }
}

注釈

メソッドは MakeArrayType 、ジェネリック型を含む任意の要素型を使用して配列型を生成する方法を提供します。

こちらもご覧ください

適用対象

.NET 10 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1