MethodAttributes Énumération
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Spécifie des indicateurs pour les attributs de méthode. Ces indicateurs sont définis dans le fichier corhdr.h.
Cette énumération prend en charge une combinaison au niveau du bit de ses valeurs membres.
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
- Héritage
- Attributs
Champs
| Nom | Valeur | Description |
|---|---|---|
| PrivateScope | 0 | Indique que le membre ne peut pas être référencé. |
| ReuseSlot | 0 | Indique que la méthode réutilisera un emplacement existant dans la table virtuelle. Il s’agit du comportement par défaut. |
| Private | 1 | Indique que la méthode est accessible uniquement à la classe actuelle. |
| FamANDAssem | 2 | Indique que la méthode est accessible aux membres de ce type et à ses types dérivés qui se trouvent dans cet assembly uniquement. |
| Assembly | 3 | Indique que la méthode est accessible à n’importe quelle classe de cet assembly. |
| Family | 4 | Indique que la méthode est accessible uniquement aux membres de cette classe et à ses classes dérivées. |
| FamORAssem | 5 | Indique que la méthode est accessible aux classes dérivées n’importe où, ainsi qu’à n’importe quelle classe dans l’assembly. |
| Public | 6 | Indique que la méthode est accessible à n’importe quel objet pour lequel cet objet est dans l’étendue. |
| MemberAccessMask | 7 | Récupère les informations d’accessibilité. |
| UnmanagedExport | 8 | Indique que la méthode managée est exportée par thunk vers du code non managé. |
| Static | 16 | Indique que la méthode est définie sur le type ; sinon, elle est définie par instance. |
| Final | 32 | Indique que la méthode ne peut pas être substituée. |
| Virtual | 64 | Indique que la méthode est virtuelle. |
| HideBySig | 128 | Indique que la méthode masque par nom et signature ; sinon, par nom uniquement. |
| NewSlot | 256 | Indique que la méthode obtient toujours un nouvel emplacement dans la table virtuelle. |
| VtableLayoutMask | 256 | Récupère les attributs de table virtuelle. |
| CheckAccessOnOverride | 512 | Indique que la méthode ne peut être substituée que lorsqu’elle est également accessible. |
| Abstract | 1024 | Indique que la classe ne fournit pas d’implémentation de cette méthode. |
| SpecialName | 2048 | Indique que la méthode est spéciale. Le nom décrit comment cette méthode est spéciale. |
| RTSpecialName | 4096 | Indique que le Common Language Runtime vérifie l’encodage du nom. |
| PinvokeImpl | 8192 | Indique que l’implémentation de la méthode est transférée via PInvoke (Platform Invocation Services). |
| HasSecurity | 16384 | Indique que la méthode a une sécurité associée. Indicateur réservé pour l’exécution uniquement. |
| RequireSecObject | 32768 | Indique que la méthode appelle une autre méthode contenant du code de sécurité. Indicateur réservé pour l’exécution uniquement. |
| ReservedMask | 53248 | Indique un indicateur réservé pour l’utilisation du runtime uniquement. |
Exemples
L’exemple suivant affiche les attributs de la méthode spécifiée.
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