Type.GetConstructorとは? わかりやすく解説

Type.GetConstructor メソッド (BindingFlags, Binder, Type[], ParameterModifier[])

指定したバインディング制約使用して指定した引数の型および修飾子一致するパラメータ設定されているコンストラクタ検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Function GetConstructor ( _
    bindingAttr As BindingFlags, _
    binder As Binder, _
    types As Type(), _
    modifiers As ParameterModifier() _
) As ConstructorInfo
Dim instance As Type
Dim bindingAttr As BindingFlags
Dim binder As Binder
Dim types As Type()
Dim modifiers As ParameterModifier()
Dim returnValue As ConstructorInfo

returnValue = instance.GetConstructor(bindingAttr, binder, types, modifiers)
[ComVisibleAttribute(true)] 
public ConstructorInfo GetConstructor (
    BindingFlags bindingAttr,
    Binder binder,
    Type[] types,
    ParameterModifier[] modifiers
)
[ComVisibleAttribute(true)] 
public:
virtual ConstructorInfo^ GetConstructor (
    BindingFlags bindingAttr, 
    Binder^ binder, 
    array<Type^>^ types, 
    array<ParameterModifier>^ modifiers
) sealed
/** @attribute ComVisibleAttribute(true) */ 
public final ConstructorInfo GetConstructor (
    BindingFlags bindingAttr, 
    Binder binder, 
    Type[] types, 
    ParameterModifier[] modifiers
)
ComVisibleAttribute(true) 
public final function GetConstructor (
    bindingAttr : BindingFlags, 
    binder : Binder, 
    types : Type[], 
    modifiers : ParameterModifier[]
) : ConstructorInfo

パラメータ

bindingAttr

検索実行方法指定する 1 つ上の BindingFlags から成るビット マスク

または

null 参照 (Visual Basic では Nothing) を返す 0。

binder

一連のプロパティ定義しバインディング有効にする Binder オブジェクトバインディングには、オーバーロードされたメソッド選択引数の型の強制変換リフレクションによるメンバ呼び出しなどが含まれます。

または

DefaultBinder を使用する場合null 参照 (Visual Basic では Nothing)。

types

取得するコンストラクタパラメータの数、順序、および型を表す Type オブジェクト配列

または

パラメータとらないコンストラクタ取得するための、Type 型の空の配列 (Type[] types = new Type[0])。

または

EmptyTypes.

modifiers

パラメータ配列内の対応する要素関連付けられている属性を表す ParameterModifier オブジェクト配列既定バインダは、このパラメータ処理しません。

戻り値
指定した要件一致するコンストラクタ存在する場合は、そのコンストラクタを表す ConstructorInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

または

modifiers多次元です。

または

typesmodifiers長さ異なります

解説解説

types 配列modifiers 配列長さが同じです。types 配列指定するパラメータには、modifiers 配列指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータ既定値を持つかどうか指定する値を表しますパラメータ関連付けられた属性メタデータ格納され相互運用性拡張します。

厳密に一致する対象存在しない場合は、一致するものを選択するために、bindertypes 配列指定されパラメータの型を強制的に変換しようとしますbinder一致するものを選択できない場合は、null 参照 (Visual Basic では Nothing) が返されます。

要求されコンストラクタパブリックではなく呼び出し元に現在のアセンブリ外の非パブリック メソッドリフレクションするための ReflectionPermission がない場合、このメソッドnull 参照 (Visual Basic では Nothing) を返します

次の BindingFlags フィルタ フラグは、検索対象含めコンストラクタ定義するために使用できます

詳細については、「System.Reflection.BindingFlags」を参照してください

このメソッド使用して初期化子 (.cctor) を取得するには、BindingFlags.Static | BindingFlags.NonPublic (Visual Basic の場合BindingFlags.StaticOrBindingFlags.NonPublic) を指定する必要があります。TypeInitializer プロパティ使用してクラス初期化子取得することもできます

メモメモ

コンストラクタおよびメソッド検索する場合パラメータ省略できません。パラメータ呼び出すときだけ省略できます

現在の Type構築ジェネリック型表している場合、このメソッドは、型パラメータ適切な型の引数置き換えて ConstructorInfo返します現在の Typeジェネリック型またはジェネリック メソッドの定義の型パラメータ表している場合、このメソッドは常に null 参照 (Visual Basic では Nothing) を返します

使用例使用例

MyClass1 クラスの型を取得し指定したバインディング フラグ一致する ConstructorInfo オブジェクト取得して、そのコンストラクタシグネチャ表示するプログラム次に示します

Imports System
Imports System.Reflection
Imports System.Security


Public Class MyClass1
    Public Sub New(ByVal
 i As Integer)
    End Sub 'New

    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(MyClass1)
            Dim types(0) As Type
            types(0) = GetType(Integer)
            ' Get the constructor that is public and takes an integer
 parameter.
            Dim constructorInfoObj As ConstructorInfo
 = _
                     myType.GetConstructor(BindingFlags.Instance Or
 _
                     BindingFlags.Public, Nothing, types, Nothing)
            If Not (constructorInfoObj Is
 Nothing) Then
                Console.WriteLine("The constructor of MyClass1
 that is " + _
                               "public and takes an integer as
 a parameter is ")
                Console.WriteLine(constructorInfoObj.ToString())
            Else
                Console.WriteLine("The constructor of MyClass1
 that is " + _
                  "public and takes an integer as a parameter
 is not available.")
            End If
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: "
 + e.Message)
        Catch e As ArgumentException
            Console.WriteLine("ArgumentException: "
 + e.Message)
        Catch e As SecurityException
            Console.WriteLine("SecurityException: "
 + e.Message)
        Catch e As Exception
            Console.WriteLine("Exception: " + e.Message)
        End Try
    End Sub
End Class
using System;
using System.Reflection;
using System.Security;


public class MyClass1
{
    public MyClass1(int i){}
    public static void Main()
    {
        try
        {
            Type myType = typeof(MyClass1);
            Type[] types = new Type[1];
            types[0] = typeof(int);
            // Get the constructor that is public and takes an integer
 parameter.
            ConstructorInfo constructorInfoObj = myType.GetConstructor(
                BindingFlags.Instance | BindingFlags.Public, null,
 types, null);
            if (constructorInfoObj != null
 )
            {
                Console.WriteLine("The constructor of MyClass1 that is public
 " +
                    "and takes an integer as a parameter is:");
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else
            {
                Console.WriteLine("The constructor of the MyClass1 that is public
 " +
                    "and takes an integer as a parameter is not available.");
            }
        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException: " + e.Message);
        }
        catch(ArgumentException e)
        {
            Console.WriteLine("ArgumentException: " + e.Message);
        }
        catch(SecurityException e)
        {
            Console.WriteLine("SecurityException: " + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Security;
public ref class MyClass1
{
public:
   MyClass1( int i ){}

};

int main()
{
   try
   {
      Type^ myType = MyClass1::typeid;
      array<Type^>^types = gcnew array<Type^>(1);
      types[ 0 ] = int::typeid;
      
      // Get the constructor that is public and takes an integer parameter.
      ConstructorInfo^ constructorInfoObj = myType->GetConstructor( static_cast<BindingFlags>(BindingFlags::Instance
 | BindingFlags::Public), nullptr, types, nullptr );
      if ( constructorInfoObj != nullptr )
      {
         Console::WriteLine( "The constructor of MyClass1 that is public
 and takes an integer as a parameter is:" );
         Console::WriteLine( constructorInfoObj );
      }
      else
      {
         Console::WriteLine( "The constructor of the MyClass1 that is public
 and takes an integer as a parameter is not available." );
      }
   }
   catch ( ArgumentNullException^ e ) 
   {
      Console::WriteLine( "ArgumentNullException: {0}", e->Message );
   }
   catch ( ArgumentException^ e ) 
   {
      Console::WriteLine( "ArgumentException: {0}", e->Message );
   }
   catch ( SecurityException^ e ) 
   {
      Console::WriteLine( "SecurityException: {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}
import System.*;
import System.Reflection.*;
import System.Security.*;

public class MyClass1
{
    public MyClass1(int i)
    {
    } //MyClass1

    public static void main(String[]
 args)
    {
        try {
            Type myType = MyClass1.class.ToType();
            Type types[] = new Type[1];
            types.set_Item(0, int.class.ToType());
            // Get the constructor that is public and takes an integer
 parameter.
            ConstructorInfo constructorInfoObj =
                myType.GetConstructor(BindingFlags.Instance
                | BindingFlags.Public,null, types, null);
            if (constructorInfoObj != null)
 {
                Console.WriteLine("The constructor of MyClass1 that is public
 "
                    + "and takes an integer as a parameter is:");
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else {
                Console.WriteLine("The constructor of the MyClass1 that"
                    + " is public "
                    + "and takes an integer as a parameter is not available.");
            }
        }
        catch (ArgumentNullException e) {
            Console.WriteLine("ArgumentNullException: " + e.get_Message());
        }
        catch (ArgumentException e) {
            Console.WriteLine("ArgumentException: " + e.get_Message());
        }
        catch (SecurityException e) {
            Console.WriteLine("SecurityException: " + e.get_Message());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: " + e.get_Message());
        }
    } //main
} //MyClass1
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
ConstructorInfo
BindingFlags
Binder
DefaultBinder
ParameterModifier
ReflectionPermission
GetConstructorImpl
GetConstructors

Type.GetConstructor メソッド (BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

指定したバインディング制約および指定した呼び出し規約使用して指定した引数の型および修飾子一致するパラメータ設定されているコンストラクタ検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Function GetConstructor ( _
    bindingAttr As BindingFlags, _
    binder As Binder, _
    callConvention As CallingConventions, _
    types As Type(), _
    modifiers As ParameterModifier() _
) As ConstructorInfo
Dim instance As Type
Dim bindingAttr As BindingFlags
Dim binder As Binder
Dim callConvention As CallingConventions
Dim types As Type()
Dim modifiers As ParameterModifier()
Dim returnValue As ConstructorInfo

returnValue = instance.GetConstructor(bindingAttr, binder, callConvention, types,
 modifiers)
[ComVisibleAttribute(true)] 
public ConstructorInfo GetConstructor (
    BindingFlags bindingAttr,
    Binder binder,
    CallingConventions callConvention,
    Type[] types,
    ParameterModifier[] modifiers
)
[ComVisibleAttribute(true)] 
public:
virtual ConstructorInfo^ GetConstructor (
    BindingFlags bindingAttr, 
    Binder^ binder, 
    CallingConventions callConvention, 
    array<Type^>^ types, 
    array<ParameterModifier>^ modifiers
) sealed
/** @attribute ComVisibleAttribute(true) */ 
public final ConstructorInfo GetConstructor (
    BindingFlags bindingAttr, 
    Binder binder, 
    CallingConventions callConvention, 
    Type[] types, 
    ParameterModifier[] modifiers
)
ComVisibleAttribute(true) 
public final function GetConstructor (
    bindingAttr : BindingFlags, 
    binder : Binder, 
    callConvention : CallingConventions, 
    types : Type[], 
    modifiers : ParameterModifier[]
) : ConstructorInfo

パラメータ

bindingAttr

検索実行方法指定する 1 つ上の BindingFlags から成るビット マスク

または

null 参照 (Visual Basic では Nothing) を返す 0。

binder

一連のプロパティ定義しバインディング有効にする Binder オブジェクトバインディングには、オーバーロードされたメソッド選択引数の型の強制変換リフレクションによるメンバ呼び出しなどが含まれます。

または

DefaultBinder を使用する場合null 参照 (Visual Basic では Nothing)。

callConvention

引数順序レイアウト戻り値を渡す方法引数格納するレジスタスタッククリーンアップに関する一連の規則指定する CallingConventions オブジェクト

types

取得するコンストラクタパラメータの数、順序、および型を表す Type オブジェクト配列

または

パラメータとらないコンストラクタ取得するための、Type 型の空の配列 (Type[] types = new Type[0])。

modifiers

types 配列内の対応する要素関連付けられている属性を表す ParameterModifier オブジェクト配列既定バインダは、このパラメータ処理しません。

戻り値
指定した要件一致するコンストラクタ存在する場合は、そのコンストラクタを表す ConstructorInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

または

modifiers多次元です。

または

typesmodifiers長さ異なります

解説解説

既定バインダParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラス使用してmodifiers処理するカスタム バインダ記述できますParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され参照渡しされるパラメータだけが処理されます。

types 配列modifiers 配列長さが同じです。types 配列指定するパラメータには、modifiers 配列指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータ既定値を持つかどうか指定する値を表しますパラメータ関連付けられた属性メタデータ格納され相互運用性拡張します。

厳密に一致する対象存在しない場合は、一致するものを選択するために、bindertypes 配列指定されパラメータの型を強制的に変換しようとしますbinder一致するものを選択できない場合は、null 参照 (Visual Basic では Nothing) が返されます。

次の BindingFlags フィルタ フラグは、検索対象含めコンストラクタ定義するために使用できます

詳細については、「System.Reflection.BindingFlags」を参照してください

このメソッド使用してクラス初期化子 (.cctor) を取得するには、BindingFlags.Static | BindingFlags.NonPublic (Visual Basic の場合BindingFlags.StaticOrBindingFlags.NonPublic) を指定する必要があります。TypeInitializer プロパティ使用してクラス初期化子取得することもできます

要求されコンストラクタパブリックではなく呼び出し元に現在のアセンブリ外の非パブリック メソッドリフレクションするための ReflectionPermission がない場合、このメソッドnull 参照 (Visual Basic では Nothing) を返します

型に対すリフレクション時に Get メソッドによって返される基本クラスメンバ次の表に示します

  1. 名前と署名による隠ぺいでは、カスタム修飾子戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約含めて署名すべての部分判断対象となります。これはバイナリ比較です。

  2. リフレクション場合プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスget アクセサset アクセサ両方を持つプロパティがあり、派生クラスには get アクセサしかない場合派生クラスプロパティにより基本クラスプロパティ隠ぺいされ、基本クラスset アクセサにはアクセスできません。

  3. カスタム属性は、共通型システム一部ではありません。

現在の Type構築ジェネリック型表している場合、このメソッドは、型パラメータ適切な型の引数置き換えて ConstructorInfo返します現在の Typeジェネリック型またはジェネリック メソッドの定義の型パラメータ表している場合、このメソッドは常に null 参照 (Visual Basic では Nothing) を返します

使用例使用例

MyClass1 の型を取得し指定したバインディング フラグ一致する ConstructorInfo オブジェクト取得してコンストラクタシグネチャ表示する例を次に示します

Public Class MyClass1
    Public Sub New(ByVal
 i As Integer)
    End Sub
    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(MyClass1)
            Dim types(0) As Type
            types(0) = GetType(Integer)
            ' Get the public instance constructor that takes an integer
 parameter.
            Dim constructorInfoObj As ConstructorInfo
 = _
                        myType.GetConstructor(BindingFlags.Instance Or
 _
                        BindingFlags.Public, Nothing, _
                        CallingConventions.HasThis, types, Nothing)
            If Not (constructorInfoObj Is
 Nothing) Then
                Console.WriteLine("The constructor of MyClass1
 that " + _
                                  "is a public instance method
 and takes an " + _
                                  "integer as a parameter is:
 ")
                Console.WriteLine(constructorInfoObj.ToString())
            Else
                Console.WriteLine("The constructor MyClass1 that
 " + _
                                  "is a public instance method
 and takes an " + _
                                  "integer as a parameter is not
 available.")
            End If
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: "
 + e.Message)
        Catch e As ArgumentException
            Console.WriteLine("ArgumentException: "
 + e.Message)
        Catch e As SecurityException
            Console.WriteLine("SecurityException: "
 + e.Message)
        Catch e As Exception
            Console.WriteLine("Exception: " + e.Message)
        End Try
    End Sub
End Class
using System;
using System.Reflection;
using System.Security;

public class MyClass1
{
    public MyClass1(int i){}
    public static void Main()
    {
        try
        {
            Type  myType = typeof(MyClass1);
            Type[] types = new Type[1];
            types[0] = typeof(int);
            // Get the public instance constructor that takes an integer
 parameter.
            ConstructorInfo constructorInfoObj = myType.GetConstructor(
                BindingFlags.Instance | BindingFlags.Public, null
,
                CallingConventions.HasThis, types, null);
            if(constructorInfoObj != null)
            {
                Console.WriteLine("The constructor of MyClass1 that is a public
 " +
                    "instance method and takes an integer as a parameter is:
 ");
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else
            {
                Console.WriteLine("The constructor of MyClass1 that is a public
 instance " +
                    "method and takes an integer as a parameter is not available.");
            }
        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException: " + e.Message);
        }
        catch(ArgumentException e)
        {
            Console.WriteLine("ArgumentException: " + e.Message);
        }
        catch(SecurityException e)
        {
            Console.WriteLine("SecurityException: " + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Security;
public ref class MyClass1
{
public:
   MyClass1( int i ){}

};

int main()
{
   try
   {
      Type^ myType = MyClass1::typeid;
      array<Type^>^types = gcnew array<Type^>(1);
      types[ 0 ] = int::typeid;
      
      // Get the public instance constructor that takes an integer parameter.
      ConstructorInfo^ constructorInfoObj = myType->GetConstructor( static_cast<BindingFlags>(BindingFlags::Instance
 | BindingFlags::Public), nullptr, CallingConventions::HasThis, types, nullptr );
      if ( constructorInfoObj != nullptr )
      {
         Console::WriteLine( "The constructor of MyClass1 that is a public
 instance method and takes an integer as a parameter is: " );
         Console::WriteLine( constructorInfoObj );
      }
      else
      {
         Console::WriteLine( "The constructor of MyClass1 that is a public
 instance method and takes an integer as a parameter is not available." );
      }
   }
   catch ( ArgumentNullException^ e ) 
   {
      Console::WriteLine( "ArgumentNullException: {0}", e->Message );
   }
   catch ( ArgumentException^ e ) 
   {
      Console::WriteLine( "ArgumentException: {0}", e->Message );
   }
   catch ( SecurityException^ e ) 
   {
      Console::WriteLine( "SecurityException: {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}
import System.*;
import System.Reflection.*;
import System.Security.*;

public class MyClass1
{
    public MyClass1(int i)
    {
    } //MyClass1

    public static void main(String[]
 args)
    {
        try {
            Type myType = MyClass1.class.ToType();
            Type types[] = new Type[1];
            types.set_Item(0, int.class.ToType());
            // Get the public instance constructor that takes an
            // integer parameter.
            ConstructorInfo constructorInfoObj =
                myType.GetConstructor(BindingFlags.Instance|BindingFlags.Public,
                null, CallingConventions.HasThis, types, null);
            if (constructorInfoObj != null)
 {
                Console.WriteLine("The constructor of MyClass1 that is a public
 "
                    + "instance method and takes an integer as a parameter is:
 ");
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else {
                Console.WriteLine("The constructor of MyClass1 that is a "
                    + "public instance method and takes an
 integer "
                    + "as a parameter is not available.");
            }
        }
        catch (ArgumentNullException e) {
            Console.WriteLine("ArgumentNullException: " + e.get_Message());
        }
        catch (ArgumentException e) {
            Console.WriteLine("ArgumentException: " + e.get_Message());
        }
        catch (SecurityException e) {
            Console.WriteLine("SecurityException: " + e.get_Message());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: " + e.get_Message());
        }
    } //main
} //MyClass1
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
ConstructorInfo
BindingFlags
Binder
DefaultBinder
CallingConventions
ParameterModifier
ReflectionPermission
GetConstructorImpl
GetConstructors

Type.GetConstructor メソッド (Type[])

指定した配列の型に一致するパラメータ設定されているパブリック インスタンス コンストラクタ検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Function GetConstructor ( _
    types As Type() _
) As ConstructorInfo
Dim instance As Type
Dim types As Type()
Dim returnValue As ConstructorInfo

returnValue = instance.GetConstructor(types)
[ComVisibleAttribute(true)] 
public ConstructorInfo GetConstructor (
    Type[] types
)
[ComVisibleAttribute(true)] 
public:
virtual ConstructorInfo^ GetConstructor (
    array<Type^>^ types
) sealed
/** @attribute ComVisibleAttribute(true) */ 
public final ConstructorInfo GetConstructor (
    Type[] types
)
ComVisibleAttribute(true) 
public final function GetConstructor (
    types : Type[]
) : ConstructorInfo

パラメータ

types

目的コンストラクタパラメータの数、順序、および型を表す Type オブジェクト配列

または

パラメータとらないコンストラクタ取得するための、Type 型の空の配列このような空の配列は、static フィールド Type.EmptyTypes によって提供されます。

戻り値
パラメータ配列の型と一致するパラメータ設定されているパブリック インスタンス コンストラクタ存在する場合は、そのコンストラクタを表す ConstructorInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

解説解説
使用例使用例

MyClass の型を取得しConstructorInfo オブジェクト取得してコンストラクタシグネチャ表示する例を次に示します

Imports System
Imports System.Reflection
Imports System.Security
Imports Microsoft.VisualBasic

Public Class MyClass1

    Public Sub New()
    End Sub 'New

    Public Sub New(ByVal
 i As Integer)
    End Sub 'New

    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(MyClass1)
            Dim types(0) As Type
            types(0) = GetType(Int32)
            ' Get the constructor that takes an integer as a parameter.
            Dim constructorInfoObj As ConstructorInfo
 = myType.GetConstructor(types)
            If Not (constructorInfoObj Is
 Nothing) Then
                Console.WriteLine("The constructor of MyClass
 that takes an integer as a parameter is: ")
                Console.WriteLine(constructorInfoObj.ToString())
            Else
                Console.WriteLine("The constructor of MyClass
 that takes no " + "parameters is not available.")
            End If

        Catch e As Exception
            Console.WriteLine("Exception caught.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        End Try
    End Sub 'Main
End Class 'MyClass1
using System;
using System.Reflection;
using System.Security;

public class MyClass1
{
    public MyClass1(){}
    public MyClass1(int i){}

    public static void Main()
    {
        try
        {
            Type myType = typeof(MyClass1);
            Type[] types = new Type[1];
            types[0] = typeof(int);
            // Get the constructor that takes an integer as a parameter.
            ConstructorInfo constructorInfoObj = myType.GetConstructor(types);
            if (constructorInfoObj != null)
            {
                Console.WriteLine("The constructor of MyClass1 that takes an
 " + 
                    "integer as a parameter is: "); 
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else
            {
                Console.WriteLine("The constructor of MyClass1 that takes an
 integer " +
                    "as a parameter is not available."); 
            }
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception caught.");
            Console.WriteLine("Source: " + e.Source);
            Console.WriteLine("Message: " + e.Message);
        }
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Security;
public ref class MyClass1
{
public:
   MyClass1(){}

   MyClass1( int i ){}

};

int main()
{
   try
   {
      Type^ myType = MyClass1::typeid;
      array<Type^>^types = gcnew array<Type^>(1);
      types[ 0 ] = int::typeid;
      
      // Get the constructor that takes an integer as a parameter.
      ConstructorInfo^ constructorInfoObj = myType->GetConstructor( types );
      if ( constructorInfoObj != nullptr )
      {
         Console::WriteLine( "The constructor of MyClass1 that takes an integer
 as a parameter is: " );
         Console::WriteLine( constructorInfoObj );
      }
      else
      {
         Console::WriteLine( "The constructor of MyClass1 that takes an integer
 as a parameter is not available." );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception caught." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }
}
import System.*;
import System.Reflection.*;
import System.Security.*;

public class MyClass1
{
    public MyClass1()
    {
    } //MyClass1

    public MyClass1(int i)
    {
    } //MyClass1

    public static void main(String[]
 args)
    {
        try {
            Type myType = MyClass1.class.ToType();
            Type types[] = new Type[1];
            types.set_Item(0, int.class.ToType());
            // Get the constructor that takes an integer as a parameter.
            ConstructorInfo constructorInfoObj = myType.GetConstructor(types);
            if (constructorInfoObj != null)
 {
                Console.WriteLine("The constructor of MyClass1 that takes an
 "
                    + "integer as a parameter is: ");
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else {
                Console.WriteLine("The constructor of MyClass1 that takes an"
                    + " integer as a parameter is not available.");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception caught.");
            Console.WriteLine("Source: " + e.get_Source());
            Console.WriteLine("Message: " + e.get_Message());
        }
    } //main
} //MyClass1
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
ConstructorInfo
DefaultBinder
ReflectionPermission
GetConstructorImpl
GetConstructors

Type.GetConstructor メソッド


_Type.GetConstructor メソッド

COM オブジェクトに、System.Type.GetConstructor メソッドへのバージョン依存しないアクセス用意されています。
オーバーロードの一覧オーバーロードの一覧

名前 説明
_Type.GetConstructor (Type[]) COM オブジェクトに、Type.GetConstructor メソッドへのバージョン依存しないアクセス用意されています。
_Type.GetConstructor (BindingFlags, Binder, Type[], ParameterModifier[]) COM オブジェクトに、Type.GetConstructor メソッドへのバージョン依存しないアクセス用意されています。
_Type.GetConstructor (BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) COM オブジェクトに、Type.GetConstructor メソッドへのバージョン依存しないアクセス用意されています。
参照参照

関連項目

_Type インターフェイス
_Type メンバ
System.Runtime.InteropServices 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からType.GetConstructorを検索した結果を表示しています。
Weblioに収録されているすべての辞書からType.GetConstructorを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からType.GetConstructor を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Type.GetConstructor」の関連用語

Type.GetConstructorのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Type.GetConstructorのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS