MethodAttributes Enum

Definisi

Menentukan bendera untuk atribut metode. Bendera ini didefinisikan dalam file corhdr.h.

Enumerasi ini mendukung kombinasi bitwise dari nilai yang termasuk di dalamnya.

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
Warisan
MethodAttributes
Atribut

Bidang

Abstract 1024

Menunjukkan bahwa kelas tidak menyediakan implementasi metode ini.

Assembly 3

Menunjukkan bahwa metode ini dapat diakses oleh kelas rakitan ini.

CheckAccessOnOverride 512

Menunjukkan bahwa metode hanya dapat ditimpa ketika juga dapat diakses.

FamANDAssem 2

Menunjukkan bahwa metode ini dapat diakses oleh anggota jenis ini dan jenis turunannya yang hanya ada di perakitan ini.

Family 4

Menunjukkan bahwa metode hanya dapat diakses oleh anggota kelas ini dan kelas turunannya.

FamORAssem 5

Menunjukkan bahwa metode ini dapat diakses oleh kelas turunan di mana saja, serta ke kelas apa pun di perakitan.

Final 32

Menunjukkan bahwa metode tidak dapat ditimpa.

HasSecurity 16384

Menunjukkan bahwa metode memiliki keamanan yang terkait dengannya. Bendera yang dicadangkan hanya untuk penggunaan runtime.

HideBySig 128

Menunjukkan bahwa metode menyembunyikan berdasarkan nama dan tanda tangan; jika tidak, hanya dengan nama.

MemberAccessMask 7

Mengambil informasi aksesibilitas.

NewSlot 256

Menunjukkan bahwa metode selalu mendapatkan slot baru di vtable.

PinvokeImpl 8192

Menunjukkan bahwa implementasi metode diteruskan melalui PInvoke (Platform Invocation Services).

Private 1

Menunjukkan bahwa metode hanya dapat diakses oleh kelas saat ini.

PrivateScope 0

Menunjukkan bahwa anggota tidak dapat dirujuk.

Public 6

Menunjukkan bahwa metode dapat diakses oleh objek apa pun yang objek ini berada dalam cakupan.

RequireSecObject 32768

Menunjukkan bahwa metode memanggil metode lain yang berisi kode keamanan. Bendera yang dicadangkan hanya untuk penggunaan runtime.

ReservedMask 53248

Menunjukkan bendera khusus untuk penggunaan runtime.

ReuseSlot 0

Menunjukkan bahwa metode akan menggunakan kembali slot yang ada di vtable. Ini adalah perilaku default.

RTSpecialName 4096

Menunjukkan bahwa runtime bahasa umum memeriksa pengodean nama.

SpecialName 2048

Menunjukkan bahwa metode ini istimewa. Nama ini menjelaskan bagaimana metode ini istimewa.

Static 16

Menunjukkan bahwa metode didefinisikan pada jenis ; jika tidak, itu didefinisikan per instans.

UnmanagedExport 8

Menunjukkan bahwa metode terkelola diekspor dengan thunk ke kode yang tidak dikelola.

Virtual 64

Menunjukkan bahwa metodenya virtual.

VtableLayoutMask 256

Mengambil atribut vtable.

Contoh

Contoh berikut menampilkan atribut metode yang ditentukan.

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

Berlaku untuk