MethodAttributes Enumeración
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Especifica marcas para los atributos de método. Estas marcas se definen en el archivo corhdr.h.
Esta enumeración admite una combinación bit a bit de sus valores de miembro.
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
- Herencia
- Atributos
Campos
| Nombre | Valor | Description |
|---|---|---|
| PrivateScope | 0 | Indica que no se puede hacer referencia al miembro. |
| ReuseSlot | 0 | Indica que el método reutilizará una ranura existente en la tabla virtual. Esta es el comportamiento predeterminado. |
| Private | 1 | Indica que el método solo es accesible para la clase actual. |
| FamANDAssem | 2 | Indica que el método solo es accesible para los miembros de este tipo y sus tipos derivados que se encuentran en este ensamblado. |
| Assembly | 3 | Indica que el método es accesible para cualquier clase de este ensamblado. |
| Family | 4 | Indica que el método solo es accesible para los miembros de esta clase y sus clases derivadas. |
| FamORAssem | 5 | Indica que el método es accesible para las clases derivadas en cualquier lugar, así como para cualquier clase del ensamblado. |
| Public | 6 | Indica que el método es accesible para cualquier objeto para el que este objeto esté en el ámbito. |
| MemberAccessMask | 7 | Recupera información de accesibilidad. |
| UnmanagedExport | 8 | Indica que thunk exporta el método administrado al código no administrado. |
| Static | 16 | Indica que el método se define en el tipo; de lo contrario, se define por instancia. |
| Final | 32 | Indica que el método no se puede invalidar. |
| Virtual | 64 | Indica que el método es virtual. |
| HideBySig | 128 | Indica que el método oculta por nombre y firma; de lo contrario, solo por nombre. |
| NewSlot | 256 | Indica que el método siempre obtiene una nueva ranura en la tabla virtual. |
| VtableLayoutMask | 256 | Recupera atributos de vtable. |
| CheckAccessOnOverride | 512 | Indica que el método solo se puede invalidar cuando también es accesible. |
| Abstract | 1024 | Indica que la clase no proporciona una implementación de este método. |
| SpecialName | 2048 | Indica que el método es especial. El nombre describe cómo este método es especial. |
| RTSpecialName | 4096 | Indica que Common Language Runtime comprueba la codificación de nombres. |
| PinvokeImpl | 8192 | Indica que la implementación del método se reenvía a través de PInvoke (Servicios de invocación de plataforma). |
| HasSecurity | 16384 | Indica que el método tiene seguridad asociada. Marca reservada solo para uso en tiempo de ejecución. |
| RequireSecObject | 32768 | Indica que el método llama a otro método que contiene código de seguridad. Marca reservada solo para uso en tiempo de ejecución. |
| ReservedMask | 53248 | Indica una marca reservada solo para uso en tiempo de ejecución. |
Ejemplos
En el ejemplo siguiente se muestran los atributos del método especificado.
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