TypeBuilder.DefineDefaultConstructor(MethodAttributes) 메서드

정의

매개 변수가 없는 생성자를 정의합니다. 여기에 정의된 생성자는 단순히 부모의 매개 변수 없는 생성자를 호출합니다.

public:
 System::Reflection::Emit::ConstructorBuilder ^ DefineDefaultConstructor(System::Reflection::MethodAttributes attributes);
public System.Reflection.Emit.ConstructorBuilder DefineDefaultConstructor(System.Reflection.MethodAttributes attributes);
[System.Runtime.InteropServices.ComVisible(true)]
public System.Reflection.Emit.ConstructorBuilder DefineDefaultConstructor(System.Reflection.MethodAttributes attributes);
member this.DefineDefaultConstructor : System.Reflection.MethodAttributes -> System.Reflection.Emit.ConstructorBuilder
[<System.Runtime.InteropServices.ComVisible(true)>]
member this.DefineDefaultConstructor : System.Reflection.MethodAttributes -> System.Reflection.Emit.ConstructorBuilder
Public Function DefineDefaultConstructor (attributes As MethodAttributes) As ConstructorBuilder

매개 변수

attributes
MethodAttributes

MethodAttributes 생성자에 적용할 특성을 나타내는 개체입니다.

반품

생성자를 반환합니다.

특성

예외

부모 형식(기본 형식)에 매개 변수가 없는 생성자가 없습니다.

이 형식은 이전에 .를 사용하여 CreateType()만들었습니다.

-또는-

현재 동적 형식의 IsGenericType 경우 속성은 true이지만 IsGenericTypeDefinition 속성은 false.

예제

다음 코드 샘플에서는 동적 형식에서 생성자의 특정 서명 및 특성을 설정하고 MSIL 모집단에 해당하는 ConstructorBuilder 특성을 반환하는 데 사용하는 DefineConstructor 방법을 보여 줍니다.

// Define the constructor.
Type[] constructorArgs = { typeof(String) };
ConstructorBuilder myConstructorBuilder =
   helloWorldTypeBuilder.DefineConstructor(MethodAttributes.Public,
                      CallingConventions.Standard, constructorArgs);
// Generate IL for the method. The constructor stores its argument in the private field.
ILGenerator myConstructorIL = myConstructorBuilder.GetILGenerator();
myConstructorIL.Emit(OpCodes.Ldarg_0);
myConstructorIL.Emit(OpCodes.Ldarg_1);
myConstructorIL.Emit(OpCodes.Stfld, myGreetingField);
myConstructorIL.Emit(OpCodes.Ret);
' Define the constructor.
Dim constructorArgs As Type() = {GetType(String)}
Dim myConstructorBuilder As ConstructorBuilder = helloWorldTypeBuilder.DefineConstructor _
                     (MethodAttributes.Public, CallingConventions.Standard, constructorArgs)
' Generate IL for the method. The constructor stores its argument in the private field.
Dim myConstructorIL As ILGenerator = myConstructorBuilder.GetILGenerator()
myConstructorIL.Emit(OpCodes.Ldarg_0)
myConstructorIL.Emit(OpCodes.Ldarg_1)
myConstructorIL.Emit(OpCodes.Stfld, myGreetingField)
myConstructorIL.Emit(OpCodes.Ret)

설명

매개 변수가 없는 생성자는 자동으로 정의되므로 다음 상황에서만 이 메서드를 호출해야 합니다.

  • 다른 생성자를 정의했으며 기본 클래스 생성자를 호출하는 매개 변수가 없는 생성자도 원합니다.

  • 매개 변수가 없는 생성자의 특성을 , Public, HideBySigSpecialNameRTSpecialName. 이외의 특성으로 설정하려고 합니다PrivateScope.

적용 대상