MethodAttributes Enumeração

Definição

Especifica sinalizadores para atributos de método. Esses sinalizadores são definidos no arquivo corhdr.h.

Essa enumeração dá suporte a uma combinação bit a bit dos valores de membro.

public enum class MethodAttributes
[System.Flags]
public enum MethodAttributes
[System.Flags]
[System.Serializable]
public enum MethodAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MethodAttributes
[<System.Flags>]
type MethodAttributes = 
[<System.Flags>]
[<System.Serializable>]
type MethodAttributes = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MethodAttributes = 
Public Enum MethodAttributes
Herança
MethodAttributes
Atributos

Campos

Nome Valor Description
PrivateScope 0

Indica que o membro não pode ser referenciado.

ReuseSlot 0

Indica que o método reutilizará um slot existente na vtable. Este é o comportamento padrão.

Private 1

Indica que o método é acessível apenas para a classe atual.

FamANDAssem 2

Indica que o método é acessível a membros desse tipo e seus tipos derivados que estão somente neste assembly.

Assembly 3

Indica que o método é acessível a qualquer classe deste assembly.

Family 4

Indica que o método é acessível apenas para membros dessa classe e suas classes derivadas.

FamORAssem 5

Indica que o método é acessível a classes derivadas em qualquer lugar, bem como a qualquer classe no assembly.

Public 6

Indica que o método é acessível a qualquer objeto para o qual este objeto está no escopo.

MemberAccessMask 7

Recupera informações de acessibilidade.

UnmanagedExport 8

Indica que o método gerenciado é exportado por thunk para código não gerenciado.

Static 16

Indica que o método é definido no tipo; caso contrário, ele é definido por instância.

Final 32

Indica que o método não pode ser substituído.

Virtual 64

Indica que o método é virtual.

HideBySig 128

Indica que o método oculta por nome e assinatura; caso contrário, somente pelo nome.

NewSlot 256

Indica que o método sempre obtém um novo slot na vtable.

VtableLayoutMask 256

Recupera atributos vtable.

CheckAccessOnOverride 512

Indica que o método só pode ser substituído quando também está acessível.

Abstract 1024

Indica que a classe não fornece uma implementação desse método.

SpecialName 2048

Indica que o método é especial. O nome descreve como esse método é especial.

RTSpecialName 4096

Indica que o common language runtime verifica a codificação de nome.

PinvokeImpl 8192

Indica que a implementação do método é encaminhada por meio do PInvoke (Platform Invocation Services).

HasSecurity 16384

Indica que o método tem segurança associada a ele. Sinalizador reservado somente para uso em runtime.

RequireSecObject 32768

Indica que o método chama outro método que contém código de segurança. Sinalizador reservado somente para uso em runtime.

ReservedMask 53248

Indica apenas um sinalizador reservado para uso em runtime.

Exemplos

O exemplo a seguir exibe os atributos do método especificado.

using System;
using System.Reflection;

class AttributesSample
{
    public void Mymethod (int int1m, out string str2m, ref string str3m)
    {
        str2m = "in Mymethod";
    }

    public static int Main(string[] args)
    {
        Console.WriteLine ("Reflection.MethodBase.Attributes Sample");

        // Get the type of the chosen class.
        Type MyType = Type.GetType("AttributesSample");

        // Get the method Mymethod on the type.
        MethodBase Mymethodbase = MyType.GetMethod("Mymethod");

        // Display the method name and signature.
        Console.WriteLine("Mymethodbase = " + Mymethodbase);

        // Get the MethodAttribute enumerated value.
        MethodAttributes Myattributes = Mymethodbase.Attributes;

        // Display the flags that are set.
        PrintAttributes(typeof(System.Reflection.MethodAttributes), (int) Myattributes);
        return 0;
    }

    public static void PrintAttributes(Type attribType, int iAttribValue)
    {
        if (!attribType.IsEnum) {Console.WriteLine("This type is not an enum."); return;}

        FieldInfo[] fields = attribType.GetFields(BindingFlags.Public | BindingFlags.Static);
        for (int i = 0; i < fields.Length; i++)
        {
            int fieldvalue = (int)fields[i].GetValue(null);
            if ((fieldvalue & iAttribValue) == fieldvalue)
            {
                Console.WriteLine(fields[i].Name);
            }
        }
    }
}
Imports System.Reflection

Class AttributesSample

    Public Sub Mymethod(ByVal int1m As Integer, ByRef str2m As String, ByRef str3m As String)
        str2m = "in Mymethod"
    End Sub


    Public Shared Function Main(ByVal args() As String) As Integer
        Console.WriteLine("Reflection.MethodBase.Attributes Sample")

        ' Get the type of a chosen class.
        Dim MyType As Type = Type.GetType("AttributesSample")

        ' Get the method Mymethod on the type.
        Dim Mymethodbase As MethodBase = MyType.GetMethod("Mymethod")

        ' Display the method name and signature.
        Console.WriteLine("Mymethodbase = {0}", Mymethodbase)

        ' Get the MethodAttribute enumerated value.
        Dim Myattributes As MethodAttributes = Mymethodbase.Attributes

        ' Display the flags that are set.
        PrintAttributes(GetType(System.Reflection.MethodAttributes), CInt(Myattributes))
        Return 0
    End Function 'Main

    Public Shared Sub PrintAttributes(ByVal attribType As Type, ByVal iAttribValue As Integer)
        If Not attribType.IsEnum Then
            Console.WriteLine("This type is not an enum.")
            Return
        End If
        Dim fields As FieldInfo() = attribType.GetFields((BindingFlags.Public Or BindingFlags.Static))
        Dim i As Integer
        For i = 0 To fields.Length - 1
            Dim fieldvalue As Integer = CType(fields(i).GetValue(Nothing), Int32)
            If (fieldvalue And iAttribValue) = fieldvalue Then
                Console.WriteLine(fields(i).Name)
            End If
        Next i
    End Sub
End Class

Aplica-se a