TypeBuilder.DefineDefaultConstructor(MethodAttributes) Yöntem
Tanım
Ö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
Parametreler
- attributes
- MethodAttributes
MethodAttributes Oluşturucuya uygulanacak öznitelikleri temsil eden bir nesne.
Döndürülenler
Oluşturucuyu döndürür.
- Öznitelikler
Özel durumlar
Üst tür (temel tür) parametresiz oluşturucuya sahip değil.
Türü daha önce kullanılarak CreateType()oluşturulmuştur.
-veya-
Geçerli dinamik tür IsGenericType için özelliği olur true, ancak IsGenericTypeDefinition özelliği olur false.
Örnekler
Aşağıdaki kod örneği, bir oluşturucunun özel imzasını ve özniteliklerini dinamik bir türe ayarlamak ve MSIL popülasyonu için karşılık gelen DefineConstructor bir döndürmek için uygulamasının kullanımını ConstructorBuilder gösterir.
// 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)
Açıklamalar
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 temel sınıf oluşturucuyu çağıran parametresiz bir oluşturucu da istiyorsunuz.
Parametresiz oluşturucudaki öznitelikleri , , PrivateScope, PublicHideBySigve SpecialNamedışında RTSpecialNamebir değere ayarlamak istiyorsunuz.