Specifies flags for method attributes. These flags are defined in the corhdr.h file.
This enumeration supports a bitwise combination of its member values.
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
Indicates that the member cannot be referenced.
ReuseSlot 0Indicates that the method will reuse an existing slot in the vtable. This is the default behavior.
Private 1Indicates that the method is accessible only to the current class.
FamANDAssem 2Indicates that the method is accessible to members of this type and its derived types that are in this assembly only.
Assembly 3Indicates that the method is accessible to any class of this assembly.
Family 4Indicates that the method is accessible only to members of this class and its derived classes.
FamORAssem 5Indicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly.
Public 6Indicates that the method is accessible to any object for which this object is in scope.
MemberAccessMask 7Retrieves accessibility information.
UnmanagedExport 8Indicates that the managed method is exported by thunk to unmanaged code.
Static 16Indicates that the method is defined on the type; otherwise, it is defined per instance.
Final 32Indicates that the method cannot be overridden.
Virtual 64Indicates that the method is virtual.
HideBySig 128Indicates that the method hides by name and signature; otherwise, by name only.
NewSlot 256Indicates that the method always gets a new slot in the vtable.
VtableLayoutMask 256Retrieves vtable attributes.
CheckAccessOnOverride 512Indicates that the method can only be overridden when it is also accessible.
Abstract 1024Indicates that the class does not provide an implementation of this method.
SpecialName 2048Indicates that the method is special. The name describes how this method is special.
RTSpecialName 4096Indicates that the common language runtime checks the name encoding.
PinvokeImpl 8192Indicates that the method implementation is forwarded through PInvoke (Platform Invocation Services).
HasSecurity 16384Indicates that the method has security associated with it. Reserved flag for runtime use only.
RequireSecObject 32768Indicates that the method calls another method containing security code. Reserved flag for runtime use only.
ReservedMask 53248Indicates a reserved flag for runtime use only.
ExamplesThe following example displays the attributes of the specified method.
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
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4