MethodBuilder.SetImplementationFlags(MethodImplAttributes) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Define os sinalizadores de implementação para esse 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
Os sinalizadores de implementação a serem definidos.
Exceções
O tipo de contenção foi criado anteriormente 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 em um corpo do 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 ...
Comentários
Ao usar o SetImplementationFlags método em combinação com o SetCustomAttribute método, lembre-se de possíveis interações. Por exemplo, usar o SetCustomAttribute método para adicionar o DllImportAttribute atributo também define o MethodImplAttributes.PreserveSig sinalizador. Se você chamar o SetImplementationFlags método posteriormente, o PreserveSig sinalizador será substituído. Existem duas formas de evitar isto:
Chame o SetImplementationFlags método antes de chamar o SetCustomAttribute método. O SetCustomAttribute método sempre respeita os sinalizadores de implementação de método existentes.
Ao definir sinalizadores de implementação, chame o GetMethodImplementationFlags método para recuperar os sinalizadores existentes, use OR bit a bit para adicionar o sinalizador e chame o SetImplementationFlags método.