MethodBuilder.SetImplementationFlags(MethodImplAttributes) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define as flags de implementação para este método.
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)
Parâmetros
- attributes
- MethodImplAttributes
As flags de implementação para definir.
Exceções
O tipo de contenção foi anteriormente criado usando CreateType().
-ou-
Para o método atual, a IsGenericMethod propriedade é true, mas a IsGenericMethodDefinition propriedade é false.
Exemplos
O exemplo de código abaixo ilustra o uso contextual do SetImplementationFlags método para descrever a implementação do MSIL num corpo de método.
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 ...
Observações
Quando usar o SetImplementationFlags método em combinação com o SetCustomAttribute método, esteja atento às potenciais interações. Por exemplo, usar o SetCustomAttribute método para adicionar o DllImportAttribute atributo também define a MethodImplAttributes.PreserveSig bandeira. Se posteriormente chamar o SetImplementationFlags método, a PreserveSig bandeira é sobrescrita. Existem duas formas de evitar isto:
Chame o SetImplementationFlags método antes de chamar o SetCustomAttribute método. O SetCustomAttribute método respeita sempre os flags de implementação existentes do método.
Quando definires flags de implementação, chama o GetMethodImplementationFlags método para recuperar as flags existentes, usa bit a bit OR para adicionar a tua flag, e depois chama o SetImplementationFlags método.