MethodAttributes Wyliczenie
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Określa flagi atrybutów metody. Te flagi są zdefiniowane 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
- Atrybuty
Pola
| Nazwa | Wartość | Opis |
|---|---|---|
| PrivateScope | 0 | Wskazuje, że nie można odwoływać się do elementu członkowskiego. |
| ReuseSlot | 0 | Wskazuje, że metoda będzie ponownie używać istniejącego miejsca w tabeli wirtualnej. Jest to zachowanie domyślne. |
| Private | 1 | Wskazuje, że metoda jest dostępna tylko dla bieżącej klasy. |
| 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. |
| Assembly | 3 | Wskazuje, że metoda jest dostępna dla dowolnej klasy tego zestawu. |
| 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 dla dowolnej klasy w zestawie. |
| Public | 6 | Wskazuje, że metoda jest dostępna dla dowolnego obiektu, dla którego ten obiekt znajduje się w zakresie. |
| MemberAccessMask | 7 | Pobiera informacje o ułatwieniach dostępu. |
| UnmanagedExport | 8 | Wskazuje, że metoda zarządzana jest eksportowana przez thunk do niezarządzanego kodu. |
| Static | 16 | Wskazuje, że metoda jest zdefiniowana na typie; w przeciwnym razie jest definiowana na wystąpienie. |
| Final | 32 | Wskazuje, że nie można zastąpić metody. |
| Virtual | 64 | Wskazuje, że metoda jest wirtualna. |
| HideBySig | 128 | Wskazuje, że metoda ukrywa się według nazwy i podpisu; w przeciwnym razie tylko według nazwy. |
| NewSlot | 256 | Wskazuje, że metoda zawsze pobiera nowe miejsce w tabeli wirtualnej. |
| VtableLayoutMask | 256 | Pobiera atrybuty tabeli wirtualnej. |
| CheckAccessOnOverride | 512 | Wskazuje, że metodę można zastąpić tylko wtedy, gdy jest ona również dostępna. |
| Abstract | 1024 | Wskazuje, że klasa nie zapewnia implementacji tej metody. |
| SpecialName | 2048 | Wskazuje, że metoda jest specjalna. Nazwa opisuje sposób, w jaki ta metoda jest specjalna. |
| RTSpecialName | 4096 | Wskazuje, że środowisko uruchomieniowe języka wspólnego sprawdza kodowanie nazw. |
| PinvokeImpl | 8192 | Wskazuje, że implementacja metody jest przekazywana za pośrednictwem funkcji PInvoke (Usługi wywołania platformy). |
| HasSecurity | 16384 | Wskazuje, że metoda ma skojarzone zabezpieczenia. Flaga zarezerwowana tylko dla środowiska uruchomieniowego. |
| 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. |
Przykłady
W poniższym przykładzie przedstawiono atrybuty określonej metody.
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