MethodBuilder.SetImplementationFlags(MethodImplAttributes) 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.
Bu yöntem için uygulama bayraklarını ayarlar.
public:
void SetImplementationFlags(System::Reflection::MethodImplAttributes attributes);
public void SetImplementationFlags(System.Reflection.MethodImplAttributes attributes);
member this.SetImplementationFlags : System.Reflection.MethodImplAttributes -> unit
Public Sub SetImplementationFlags (attributes As MethodImplAttributes)
Parametreler
- attributes
- MethodImplAttributes
Ayarlanacağı uygulama bayrakları.
Özel durumlar
İçeren tür daha önce kullanılarak CreateType()oluşturulmuştur.
-veya-
Geçerli yöntem IsGenericMethod için özelliği şeklindedir true, ancak IsGenericMethodDefinition özelliği şeklindedir false.
Örnekler
Aşağıdaki kod örneği, bir yöntem gövdesinde SetImplementationFlags MSIL uygulamasını açıklamak için yönteminin bağlamsal kullanımını gösterir.
MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("MyMethod",
MethodAttributes.Public,
CallingConventions.HasThis,
typeof(int),
new Type[] { typeof(int),
typeof(int) });
// Specifies that the dynamic method declared above has a an MSIL implementation,
// is managed, synchronized (single-threaded) through the body, and that it
// cannot be inlined.
myMthdBuilder.SetImplementationFlags(MethodImplAttributes.IL |
MethodImplAttributes.Managed |
MethodImplAttributes.Synchronized |
MethodImplAttributes.NoInlining);
// Create an ILGenerator for the MethodBuilder and emit MSIL here ...
Dim myMthdBuilder As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod", _
MethodAttributes.Public, _
CallingConventions.HasThis, _
GetType(Integer), _
New Type() {GetType(Integer), GetType(Integer)})
' Specifies that the dynamic method declared above has a an MSIL implementation,
' is managed, synchronized (single-threaded) through the body, and that it
' cannot be inlined.
myMthdBuilder.SetImplementationFlags((MethodImplAttributes.IL Or _
MethodImplAttributes.Managed Or _
MethodImplAttributes.Synchronized Or _
MethodImplAttributes.NoInlining))
' Create an ILGenerator for the MethodBuilder and emit MSIL here ...
Açıklamalar
yöntemini yöntemiyle SetCustomAttribute birlikte kullandığınızda SetImplementationFlags olası etkileşimlere dikkat edin. Örneğin, SetCustomAttribute özniteliğini eklemek DllImportAttribute için yöntemini kullanmak bayrağını MethodImplAttributes.PreserveSig da ayarlar. Daha sonra yöntemini çağırırsanız SetImplementationFlags bayrağın PreserveSig üzerine yazılır. Bunu önlemenin iki yolu vardır:
SetImplementationFlags yöntemini çağırmadan önce yöntemini çağırınSetCustomAttribute. SetCustomAttribute yöntemi her zaman mevcut yöntem uygulama bayraklarını dikkate alır.
Uygulama bayraklarını ayarladığınızda GetMethodImplementationFlags , mevcut bayrakları almak için yöntemini çağırın, bit düzeyinde OR kullanarak bayrağınızı ekleyin ve yöntemini çağırın SetImplementationFlags .