MethodAttributes Enumeráció
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
A metódusattribútumok jelzőit adja meg. Ezek a jelzők a corhdr.h fájlban vannak definiálva.
Ez a felsorolás támogatja a tagértékek bitenkénti kombinációját.
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
- Öröklődés
- Attribútumok
Mezők
| Name | Érték | Description |
|---|---|---|
| PrivateScope | 0 | Azt jelzi, hogy a tagra nem lehet hivatkozni. |
| ReuseSlot | 0 | Azt jelzi, hogy a metódus újra felhasznál egy meglévő pontot a virtuális táblában. Ez az alapértelmezett viselkedés. |
| Private | 1 | Azt jelzi, hogy a metódus csak az aktuális osztály számára érhető el. |
| FamANDAssem | 2 | Azt jelzi, hogy a metódus elérhető az ilyen típusú tagok és az ebben a szerelvényben található származtatott típusok számára. |
| Assembly | 3 | Azt jelzi, hogy a metódus elérhető a szerelvény bármely osztálya számára. |
| Family | 4 | Azt jelzi, hogy a metódus csak az osztály tagjai és származtatott osztályai számára érhető el. |
| FamORAssem | 5 | Azt jelzi, hogy a metódus bárhonnan elérhető a származtatott osztályokhoz, valamint a szerelvény bármely osztályához. |
| Public | 6 | Azt jelzi, hogy a metódus minden olyan objektum számára elérhető, amelyhez ez az objektum hatókörben van. |
| MemberAccessMask | 7 | Lekéri az akadálymentességi információkat. |
| UnmanagedExport | 8 | Azt jelzi, hogy a felügyelt metódust a rendszer nem felügyelt kódba exportálja. |
| Static | 16 | Azt jelzi, hogy a metódus a típuson van definiálva; ellenkező esetben példányonként van definiálva. |
| Final | 32 | Azt jelzi, hogy a metódus nem bírálható felül. |
| Virtual | 64 | Azt jelzi, hogy a metódus virtuális. |
| HideBySig | 128 | Azt jelzi, hogy a metódus név és aláírás alapján rejt el; egyéb esetben csak név alapján. |
| NewSlot | 256 | Azt jelzi, hogy a metódus mindig kap egy új pontot a virtuális táblában. |
| VtableLayoutMask | 256 | Vtable attribútumokat kér le. |
| CheckAccessOnOverride | 512 | Azt jelzi, hogy a metódus csak akkor bírálható felül, ha az is elérhető. |
| Abstract | 1024 | Azt jelzi, hogy az osztály nem biztosítja ennek a metódusnak a megvalósítását. |
| SpecialName | 2048 | Azt jelzi, hogy a metódus különleges. A név leírja, hogyan különleges ez a módszer. |
| RTSpecialName | 4096 | Azt jelzi, hogy a közös nyelvi futtatókörnyezet ellenőrzi a névkódolást. |
| PinvokeImpl | 8192 | Azt jelzi, hogy a metódus implementációja a PInvoke (Platform Invocation Services) szolgáltatáson keresztül történik. |
| HasSecurity | 16384 | Azt jelzi, hogy a metódushoz biztonsági társítás tartozik. Fenntartott jelölő csak futásidejű használatra. |
| RequireSecObject | 32768 | Azt jelzi, hogy a metódus egy másik, biztonsági kódot tartalmazó metódust hív meg. Fenntartott jelölő csak futásidejű használatra. |
| ReservedMask | 53248 | Csak futtatókörnyezeti használatra fenntartott jelzőt jelöl. |
Példák
Az alábbi példa a megadott metódus attribútumait jeleníti meg.
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