MethodAttributes Enumerazione
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica i flag per gli attributi del metodo. Questi flag sono definiti nel file corhdr.h.
Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.
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
- Ereditarietà
- Attributi
Campi
| Nome | Valore | Descrizione |
|---|---|---|
| PrivateScope | 0 | Indica che non è possibile fare riferimento al membro. |
| ReuseSlot | 0 | Indica che il metodo riutilizza uno slot esistente nella tabella virtuale. Si tratta del comportamento predefinito. |
| Private | 1 | Indica che il metodo è accessibile solo alla classe corrente. |
| FamANDAssem | 2 | Indica che il metodo è accessibile ai membri di questo tipo e ai relativi tipi derivati che si trovano solo in questo assembly. |
| Assembly | 3 | Indica che il metodo è accessibile a qualsiasi classe di questo assembly. |
| Family | 4 | Indica che il metodo è accessibile solo ai membri di questa classe e alle relative classi derivate. |
| FamORAssem | 5 | Indica che il metodo è accessibile alle classi derivate ovunque, nonché a qualsiasi classe nell'assembly. |
| Public | 6 | Indica che il metodo è accessibile a qualsiasi oggetto per il quale questo oggetto si trova nell'ambito. |
| MemberAccessMask | 7 | Recupera informazioni sull'accessibilità. |
| UnmanagedExport | 8 | Indica che il metodo gestito viene esportato da thunk in codice non gestito. |
| Static | 16 | Indica che il metodo è definito nel tipo; in caso contrario, viene definito per ogni istanza. |
| Final | 32 | Indica che il metodo non può essere sottoposto a override. |
| Virtual | 64 | Indica che il metodo è virtuale. |
| HideBySig | 128 | Indica che il metodo nasconde in base al nome e alla firma; in caso contrario, solo per nome. |
| NewSlot | 256 | Indica che il metodo ottiene sempre un nuovo slot nella tabella virtuale. |
| VtableLayoutMask | 256 | Recupera gli attributi della tabella virtuale. |
| CheckAccessOnOverride | 512 | Indica che il metodo può essere sottoposto a override solo quando è accessibile anche. |
| Abstract | 1024 | Indica che la classe non fornisce un'implementazione di questo metodo. |
| SpecialName | 2048 | Indica che il metodo è speciale. Il nome descrive come questo metodo è speciale. |
| RTSpecialName | 4096 | Indica che Common Language Runtime controlla la codifica dei nomi. |
| PinvokeImpl | 8192 | Indica che l'implementazione del metodo viene inoltrata tramite PInvoke (Platform Invocation Services). |
| HasSecurity | 16384 | Indica che al metodo è associata la sicurezza. Flag riservato solo per l'uso in fase di esecuzione. |
| RequireSecObject | 32768 | Indica che il metodo chiama un altro metodo contenente il codice di sicurezza. Flag riservato solo per l'uso in fase di esecuzione. |
| ReservedMask | 53248 | Indica un flag riservato solo per l'uso in fase di esecuzione. |
Esempio
Nell'esempio seguente vengono visualizzati gli attributi del metodo specificato.
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