System.Type.GetConstructor Method

Searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention.

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public System.Reflection.ConstructorInfo GetConstructor (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConvention, Type[] types, System.Reflection.ParameterModifier[] modifiers)

Parameters

bindingAttr
A bitmask comprised of one or more System.Reflection.BindingFlags that specify how the search is conducted.
binder
An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection.
callConvention
The object that specifies the set of rules to use regarding the order and layout of arguments, how the return value is passed, what registers are used for arguments, and the stack is cleaned up.
types
An array of Type objects representing the number, order, and type of the parameters for the constructor to get.
modifiers
An array of System.Reflection.ParameterModifier objects representing the attributes associated with the corresponding element in the types array. The default binder does not process this parameter.

Returns

An object representing the constructor that matches the specified requirements, if found; otherwise, null.

Remarks

Although the default binder does not process System.Reflection.ParameterModifier (the modifiers parameter), you can use the abstract System.Reflection.Binder class to write a custom binder that does process modifiers. ParameterModifier is only used when calling through COM interop, and only parameters that are passed by reference are handled.

If an exact match does not exist, the binder will attempt to coerce the parameter types specified in the types array in order to select a match. If the binder is unable to select a match, then null is returned.

The following System.Reflection.BindingFlags filter flags can be used to define which constructors to include in the search:

  • You must specify either BindingFlags.Instance or BindingFlags.Static in order to get a return.

  • Specify BindingFlags.Public to include public constructors in the search.

  • Specify BindingFlags.NonPublic to include non-public constructors (that is, private, internal, and protected constructors) in the search.

See System.Reflection.BindingFlags for more information.

To get the class initializer (.cctor) using this method, you must specify System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic (System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.NonPublic in Visual Basic). You can also get the class initializer using the Type.TypeInitializer property.

The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

Constructor

No

No

Field

No

Yes. A field is always hide-by-name-and-signature.

Event

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

Method

No

Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.

Nested Type

No

No

Property

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

[The 'ordered' type of list has not been implemented in the ECMA stylesheet.]
Note:

You cannot omit parameters when looking up constructors and methods. You can only omit parameters when invoking.

If the current Type represents a constructed generic type, this method returns the System.Reflection.ConstructorInfo with the type parameters replaced by the appropriate type arguments. If the current Type represents a type parameter in the definition of a generic type or generic method, this method always returns null.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0