MethodAttributes Výčet

Definice

Určuje příznaky pro atributy metody. Tyto příznaky jsou definovány v souboru corhdr.h.

Tento výčet podporuje bitové kombinace hodnot jeho členů.

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
Dědičnost
MethodAttributes
Atributy

Pole

Abstract 1024

Označuje, že třída neposkytuje implementaci této metody.

Assembly 3

Označuje, že metoda je přístupná pro libovolnou třídu tohoto sestavení.

CheckAccessOnOverride 512

Označuje, že metodu lze přepsat pouze v případě, že je také přístupná.

FamANDAssem 2

Označuje, že metoda je přístupná členům tohoto typu a jeho odvozeným typům, které jsou pouze v tomto sestavení.

Family 4

Označuje, že metoda je přístupná pouze členům této třídy a jejích odvozených tříd.

FamORAssem 5

Označuje, že metoda je přístupná pro odvozené třídy kdekoli, stejně jako pro jakoukoli třídu v sestavení.

Final 32

Označuje, že metodu nelze přepsat.

HasSecurity 16384

Označuje, že metoda má přidružené zabezpečení. Rezervovaný příznak pouze pro použití za běhu.

HideBySig 128

Označuje, že metoda skryje podle názvu a podpisu; jinak pouze podle názvu.

MemberAccessMask 7

Načte informace o přístupnosti.

NewSlot 256

Označuje, že metoda vždy získá nový slot ve virtuální tabulce.

PinvokeImpl 8192

Označuje, že implementace metody se předává prostřednictvím PInvoke (Platform Invocation Services).

Private 1

Označuje, že metoda je přístupná pouze pro aktuální třídu.

PrivateScope 0

Označuje, že na člen nelze odkazovat.

Public 6

Označuje, že metoda je přístupná pro jakýkoli objekt, pro který je tento objekt v oboru.

RequireSecObject 32768

Označuje, že metoda volá jinou metodu obsahující bezpečnostní kód. Rezervovaný příznak pouze pro použití za běhu.

ReservedMask 53248

Označuje rezervovaný příznak pouze pro použití za běhu.

ReuseSlot 0

Označuje, že metoda znovu použije existující slot ve virtuální tabulce. Toto je výchozí chování.

RTSpecialName 4096

Označuje, že modul CLR (Common Language Runtime) kontroluje kódování názvu.

SpecialName 2048

Označuje, že metoda je zvláštní. Název popisuje, jak je tato metoda speciální.

Static 16

Označuje, že metoda je definována na typu; v opačném případě se definuje pro jednotlivé instance.

UnmanagedExport 8

Označuje, že spravovaná metoda je exportována pomocí tmy do nespravovaného kódu.

Virtual 64

Označuje, že metoda je virtuální.

VtableLayoutMask 256

Načte atributy vtable.

Příklady

Následující příklad zobrazuje atributy zadané 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

Platí pro