Type.GetConstructor メソッド (BindingFlags, Binder, Type[], ParameterModifier[])
アセンブリ: 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.
指定した要件と一致するコンストラクタが存在する場合は、そのコンストラクタを表す ConstructorInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
厳密に一致する対象が存在しない場合は、一致するものを選択するために、binder は types 配列で指定されたパラメータの型を強制的に変換しようとします。binder が一致するものを選択できない場合は、null 参照 (Visual Basic では Nothing) が返されます。
要求されたコンストラクタがパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック メソッドをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
次の BindingFlags フィルタ フラグは、検索対象に含めるコンストラクタを定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないコンストラクタ (つまり、プライベート コンストラクタやプロテクト コンストラクタ) を含めるための BindingFlags.NonPublic を指定します。
詳細については、「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


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetConstructor メソッド (BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])
アセンブリ: 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])。
指定した要件と一致するコンストラクタが存在する場合は、そのコンストラクタを表す ConstructorInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


既定のバインダは ParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラスを使用してmodifiers を処理するカスタム バインダを記述できます。ParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され、参照渡しされるパラメータだけが処理されます。
types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
厳密に一致する対象が存在しない場合は、一致するものを選択するために、binder は types 配列で指定されたパラメータの型を強制的に変換しようとします。binder が一致するものを選択できない場合は、null 参照 (Visual Basic では Nothing) が返されます。
次の BindingFlags フィルタ フラグは、検索対象に含めるコンストラクタを定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないコンストラクタ (つまり、プライベート コンストラクタやプロテクト コンストラクタ) を含めるための BindingFlags.NonPublic を指定します。
詳細については、「System.Reflection.BindingFlags」を参照してください。
このメソッドを使用してクラス初期化子 (.cctor) を取得するには、BindingFlags.Static | BindingFlags.NonPublic (Visual Basic の場合は BindingFlags.StaticOrBindingFlags.NonPublic) を指定する必要があります。TypeInitializer プロパティを使用して、クラス初期化子を取得することもできます。
要求されたコンストラクタがパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック メソッドをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
現在の 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


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetConstructor メソッド (Type[])
アセンブリ: 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: virtual ConstructorInfo^ GetConstructor ( array<Type^>^ types ) sealed
/** @attribute ComVisibleAttribute(true) */ public final ConstructorInfo GetConstructor ( Type[] types )
- types
目的のコンストラクタのパラメータの数、順序、および型を表す Type オブジェクトの配列。
または
パラメータをとらないコンストラクタを取得するための、Type 型の空の配列。このような空の配列は、static フィールド Type.EmptyTypes によって提供されます。
パラメータ型配列の型と一致するパラメータが設定されているパブリック インスタンス コンストラクタが存在する場合は、そのコンストラクタを表す ConstructorInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


このメソッド オーバーロードは、パブリック インスタンス コンストラクタを検索しますが、クラス初期化子を取得するためには使用できません。クラス初期化子を取得するには、BindingFlags をとるオーバーロードを使用し、BindingFlags.Static | BindingFlags.NonPublic (Visual Basic の場合は BindingFlags.StaticOrBindingFlags.NonPublic) を指定します。TypeInitializer プロパティを使用して、クラス初期化子を取得することもできます。
要求されたコンストラクタがパブリックでない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
![]() |
---|
現在の Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて ConstructorInfo を返します。現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドは常に null 参照 (Visual Basic では Nothing) を返します。

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetConstructor メソッド

名前 | 説明 |
---|---|
Type.GetConstructor (Type[]) | 指定した配列の型に一致するパラメータが設定されているパブリック インスタンス コンストラクタを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetConstructor (BindingFlags, Binder, Type[], ParameterModifier[]) | 指定したバインディング制約を使用して、指定した引数の型および修飾子と一致するパラメータが設定されているコンストラクタを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetConstructor (BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) | 指定したバインディング制約および指定した呼び出し規約を使用して、指定した引数の型および修飾子と一致するパラメータが設定されているコンストラクタを検索します。 |

_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 メソッドへのバージョンに依存しないアクセスが用意されています。 |

Weblioに収録されているすべての辞書からType.GetConstructorを検索する場合は、下記のリンクをクリックしてください。

- Type.GetConstructorのページへのリンク