MethodBuilder.SetImplementationFlags(MethodImplAttributes) Метод
Определение
Задает флаги реализации для этого метода.Sets the implementation flags for this method.
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)
Параметры
- attributes
- MethodImplAttributes
Флаги реализации для установки.The implementation flags to set.
Исключения
Содержащий тип был создан ранее с помощью CreateType().The containing type was previously created using CreateType().
-или--or-
Для текущего метода свойство IsGenericMethod имеет значение true
, но свойство IsGenericMethodDefinition имеет значение false
.For the current method, the IsGenericMethod property is true
, but the IsGenericMethodDefinition property is false
.
Примеры
В приведенном ниже примере кода показано контекстное использование SetImplementationFlags
метода для описания реализации MSIL в теле метода.The code sample below illustrates the contextual use of the SetImplementationFlags
method to describe the implementation of MSIL in a method body.
array<Type^>^ temp0 = { int::typeid, int::typeid };
MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod",
MethodAttributes::Public,
CallingConventions::HasThis,
int::typeid,
temp0 );
// 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)(
MethodImplAttributes::IL |
MethodImplAttributes::Managed |
MethodImplAttributes::Synchronized |
MethodImplAttributes::NoInlining) );
// Create an ILGenerator for the MethodBuilder and emit MSIL here ...
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 ...
Комментарии
При использовании SetImplementationFlags метода в сочетании с SetCustomAttribute методом следует учитывать возможные взаимодействия.When you use the SetImplementationFlags method in combination with the SetCustomAttribute method, be aware of potential interactions. Например, при помощи SetCustomAttribute метода для добавления DllImportAttribute атрибута также устанавливается MethodImplAttributes.PreserveSig флаг.For example, using the SetCustomAttribute method to add the DllImportAttribute attribute also sets the MethodImplAttributes.PreserveSig flag. При последующем вызове SetImplementationFlags метода этот PreserveSig флаг перезаписывается.If you subsequently call the SetImplementationFlags method, the PreserveSig flag is overwritten. Этого можно избежать двумя способами:There are two ways to avoid this:
Вызовите SetImplementationFlags метод перед вызовом SetCustomAttribute метода.Call the SetImplementationFlags method before you call the SetCustomAttribute method. SetCustomAttributeМетод всегда учитывает существующие флаги реализации метода.The SetCustomAttribute method always respects existing method implementation flags.
При установке флагов реализации вызовите GetMethodImplementationFlags метод, чтобы получить существующие флаги, используйте битовую операцию или, чтобы добавить флаг, а затем вызовите SetImplementationFlags метод.When you set implementation flags, call the GetMethodImplementationFlags method to retrieve the existing flags, use bitwise OR to add your flag, and then call the SetImplementationFlags method.