MethodAttributes Wyliczenie

Definicja

Określa flagi atrybutów metody. Te flagi są definiowane w pliku corhdr.h.

To wyliczenie obsługuje bitową kombinację jego wartości składowych.

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
Dziedziczenie
MethodAttributes
Atrybuty

Pola

Abstract 1024

Wskazuje, że klasa nie zapewnia implementacji tej metody.

Assembly 3

Wskazuje, że metoda jest dostępna dla dowolnej klasy tego zestawu.

CheckAccessOnOverride 512

Wskazuje, że metoda może być zastępowana tylko wtedy, gdy jest dostępna.

FamANDAssem 2

Wskazuje, że metoda jest dostępna dla elementów członkowskich tego typu i jego typów pochodnych, które znajdują się tylko w tym zestawie.

Family 4

Wskazuje, że metoda jest dostępna tylko dla składowych tej klasy i jej klas pochodnych.

FamORAssem 5

Wskazuje, że metoda jest dostępna dla klas pochodnych w dowolnym miejscu, a także do dowolnej klasy w zestawie.

Final 32

Wskazuje, że nie można zastąpić metody.

HasSecurity 16384

Wskazuje, że metoda ma skojarzone zabezpieczenia. Flaga zarezerwowana tylko dla środowiska uruchomieniowego.

HideBySig 128

Wskazuje, że metoda ukrywa się według nazwy i podpisu; w przeciwnym razie tylko według nazwy.

MemberAccessMask 7

Pobiera informacje o ułatwieniach dostępu.

NewSlot 256

Wskazuje, że metoda zawsze pobiera nowe miejsce w tabeli wirtualnej.

PinvokeImpl 8192

Wskazuje, że implementacja metody jest przekazywana za pośrednictwem funkcji PInvoke (Usługi wywołania platformy).

Private 1

Wskazuje, że metoda jest dostępna tylko dla bieżącej klasy.

PrivateScope 0

Wskazuje, że nie można odwoływać się do elementu członkowskiego.

Public 6

Wskazuje, że metoda jest dostępna dla dowolnego obiektu, dla którego ten obiekt znajduje się w zakresie.

RequireSecObject 32768

Wskazuje, że metoda wywołuje inną metodę zawierającą kod zabezpieczeń. Flaga zarezerwowana tylko dla środowiska uruchomieniowego.

ReservedMask 53248

Wskazuje flagę zarezerwowaną tylko dla środowiska uruchomieniowego.

ReuseSlot 0

Wskazuje, że metoda ponownie użyje istniejącego miejsca w tabeli wirtualnej. Jest to zachowanie domyślne.

RTSpecialName 4096

Wskazuje, że środowisko uruchomieniowe języka wspólnego sprawdza kodowanie nazw.

SpecialName 2048

Wskazuje, że metoda jest specjalna. Nazwa opisuje, jak ta metoda jest specjalna.

Static 16

Wskazuje, że metoda jest zdefiniowana w typie; w przeciwnym razie jest definiowana na wystąpienie.

UnmanagedExport 8

Wskazuje, że metoda zarządzana jest eksportowana przez thunk do niezarządzanego kodu.

Virtual 64

Wskazuje, że metoda jest wirtualna.

VtableLayoutMask 256

Pobiera atrybuty tabeli wirtualnej.

Przykłady

Poniższy przykład przedstawia atrybuty określonej metody.

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

public ref class AttributesSample
{
public:
   void Mymethod( int int1m, [Out]interior_ptr<String^> str2m, interior_ptr<String^> str3m )
   {
       *str2m = "in Mymethod";
   }
};

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

   array<FieldInfo^>^fields = attribType->GetFields( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
   for ( int i = 0; i < fields->Length; i++ )
   {
      int fieldvalue = safe_cast<Int32>(fields[ i ]->GetValue( nullptr ));
      if ( (fieldvalue & iAttribValue) == fieldvalue )
      {
         Console::WriteLine( fields[ i ]->Name );
      }
   }
}

int main()
{
   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 = {0}", Mymethodbase );

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

   // Display the flags that are set.
   PrintAttributes( System::Reflection::MethodAttributes::typeid, (int)Myattributes );
   return 0;
}
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

Dotyczy