TypeBuilder.DefineDefaultConstructor(MethodAttributes) Yöntem
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Parametresiz oluşturucuyu tanımlar. Burada tanımlanan oluşturucu yalnızca üst öğesinin parametresiz oluşturucuyu çağırır.
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
Oluşturucuya uygulanacak öznitelikleri temsil eden bir nesne.
Oluşturucuyu döndürür.
- Öznitelikler
Üst türün (temel tür) parametresiz oluşturucu yok.
Türü daha önce kullanılarak CreateType()oluşturulmuştur.
-veya-
Geçerli dinamik türü için IsGenericType özelliği şeklindedir true
, ancak IsGenericTypeDefinition özelliği şeklindedir false
.
Aşağıdaki kod örneği, bir oluşturucunun belirli imzasını ve özniteliklerini dinamik bir türe ayarlamak ve MSIL popülasyonu için karşılık gelen ConstructorBuilder bir döndürmek için uygulamasının kullanımını DefineConstructor
gösterir.
// Define the constructor.
array<Type^>^ constructorArgs = {String::typeid};
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.
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)
Parametresiz oluşturucu otomatik olarak tanımlandığından, bu yöntemi yalnızca aşağıdaki durumlarda çağırmak gerekir:
Başka bir oluşturucu tanımladığınız gibi, yalnızca temel sınıf oluşturucuyu çağıran parametresiz bir oluşturucu da istiyorsunuz.
Parametresiz oluşturucudaki öznitelikleri , , Public, SpecialNameHideBySigve RTSpecialNamedışında PrivateScopebir değere ayarlamak istiyorsunuz.
Ürün | Sürümler |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided), 2.1 |
.NET geri bildirimi
.NET, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: