共用方式為


TypeBuilder.DefineDefaultConstructor Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Defines the default constructor. The constructor defined here will simply call the default constructor of the parent.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Function DefineDefaultConstructor ( _
    attributes As MethodAttributes _
) As ConstructorBuilder
[ComVisibleAttribute(true)]
public ConstructorBuilder DefineDefaultConstructor(
    MethodAttributes attributes
)

Parameters

Return Value

Type: System.Reflection.Emit.ConstructorBuilder
The defined constructor.

Exceptions

Exception Condition
NotSupportedException

The parent type (base type) does not have a default constructor.

InvalidOperationException

The type was previously created using CreateType.

-or-

For the current dynamic type, the IsGenericType property is true, but the IsGenericTypeDefinition property is false.

-or-

The current type is an interface.

Remarks

Because the default constructor is automatically defined, it is necessary to call this method only in the following situations:

  • You have defined another constructor and you also want a default constructor that simply calls the base class constructor.

  • You want to set the attributes on the default constructor to something other than PrivateScope, Public, HideBySig, SpecialName, and RTSpecialName.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.