MethodInfo 類別

定義

探索方法的屬性 (Attribute) 並提供方法中繼資料 (Metadata) 的存取。Discovers the attributes of a method and provides access to method metadata.

public ref class MethodInfo abstract : System::Reflection::MethodBase, System::Runtime::InteropServices::_MethodInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public abstract class MethodInfo : System.Reflection.MethodBase, System.Runtime.InteropServices._MethodInfo
type MethodInfo = class
    inherit MethodBase
    interface _MethodInfo
Public MustInherit Class MethodInfo
Inherits MethodBase
Implements _MethodInfo
繼承
衍生
屬性
實作

備註

MethodInfo類別代表類型的方法。The MethodInfo class represents a method of a type. 您可以使用MethodInfo物件來取得物件所代表之方法的相關資訊,以及叫用方法。You can use a MethodInfo object to obtain information about the method that the object represents and to invoke the method. 例如:For example:

您可以藉由MethodInfo Type.GetMethods呼叫或Type.GetMethod MethodInfo.MakeGenericMethod 方法MethodInfo ,或呼叫代表泛型方法定義之物件的方法,來具現化實例。You can instantiate a MethodInfo instances by calling the Type.GetMethods or Type.GetMethod method, or by calling the MethodInfo.MakeGenericMethod method of a MethodInfo object that represents a generic method definition.

如需泛型方法特有之詞彙的不變條件清單,請參閱IsGenericMethod屬性。For a list of the invariant conditions for terms specific to generic methods, see the IsGenericMethod property. 如需一般反映中使用之其他詞彙的非變異條件清單,請參閱IsGenericType屬性。For a list of the invariant conditions for other terms used in generic reflection, see the IsGenericType property.

給繼承者的注意事項

當您繼承自MethodInfo時,您必須GetBaseDefinition()ReturnTypeReturnTypeCustomAttributesGetParameters() GetMethodImplementationFlags() MethodHandle Attributes 、、Name、、 、Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)、、、 、MemberType DeclaringType、 、ReflectedType 、和GetCustomAttributes(Type, Boolean)GetCustomAttributes(Boolean) IsDefined(Type, Boolean)When you inherit from MethodInfo, you must override GetBaseDefinition(), ReturnType, ReturnTypeCustomAttributes, GetParameters(), GetMethodImplementationFlags(), MethodHandle, Attributes, Invoke(Object, BindingFlags, Binder, Object[], CultureInfo), Name, MemberType, DeclaringType, ReflectedType, GetCustomAttributes(Boolean), GetCustomAttributes(Type, Boolean), and IsDefined(Type, Boolean).

建構函式

MethodInfo()

初始化 MethodInfo 類別的新執行個體。Initializes a new instance of the MethodInfo class.

屬性

Attributes

取得與這個方法相關的屬性 (Attribute)。Gets the attributes associated with this method.

(繼承來源 MethodBase)
CallingConvention

取得值,指出這個方法的呼叫慣例。Gets a value indicating the calling conventions for this method.

(繼承來源 MethodBase)
ContainsGenericParameters

取得值,指出泛型方法是否包含未指派的泛型型別參數。Gets a value that indicates whether a generic method contains unassigned generic type parameters.

CustomAttributes

取得包含此成員之自訂屬性的集合。Gets a collection that contains this member's custom attributes.

(繼承來源 MemberInfo)
DeclaringType

取得宣告這個成員的類別。Gets the class that declares this member.

(繼承來源 MemberInfo)
IsAbstract

取得值,指出方法是否為抽象。Gets a value indicating whether the method is abstract.

(繼承來源 MethodBase)
IsAssembly

取得值,指出 Assembly 是否描述此方法或建構函式 (Constructor) 的潛在可視性;亦即,最多只有相同組件 (Assembly) 中的其他型別可以看見該方法或建構函式,組件外部的衍生型別 (Derived Type) 則看不見它們。Gets a value indicating whether the potential visibility of this method or constructor is described by Assembly; that is, the method or constructor is visible at most to other types in the same assembly, and is not visible to derived types outside the assembly.

(繼承來源 MethodBase)
IsCollectible

取得指出此 MemberInfo 物件是否為可回收 AssemblyLoadContext 中保存之組件一部分的值。Gets a value that indicates whether this MemberInfo object is part of an assembly held in a collectible AssemblyLoadContext.

(繼承來源 MemberInfo)
IsConstructedGenericMethod (繼承來源 MethodBase)
IsConstructor

取得值,指出方法是否為建構函示。Gets a value indicating whether the method is a constructor.

(繼承來源 MethodBase)
IsFamily

取得值,指出 Family 是否描述此方法或建構函式的可視性;亦即,您只能在其類別和衍生類別內看見該方法或建構函式。Gets a value indicating whether the visibility of this method or constructor is described by Family; that is, the method or constructor is visible only within its class and derived classes.

(繼承來源 MethodBase)
IsFamilyAndAssembly

取得值,指出 FamANDAssem 是否描述此方法或建構函式的可視性;亦即,只有當該方法或建構函式位於相同的組件時,衍生類別才能呼叫它們。Gets a value indicating whether the visibility of this method or constructor is described by FamANDAssem; that is, the method or constructor can be called by derived classes, but only if they are in the same assembly.

(繼承來源 MethodBase)
IsFamilyOrAssembly

取得值,指出 FamORAssem 是否描述此方法或建構函式的潛在可視性;亦即,無論該方法或建構函式位於何處,衍生類別以及相同組件中的類別都可以呼叫它們。Gets a value indicating whether the potential visibility of this method or constructor is described by FamORAssem; that is, the method or constructor can be called by derived classes wherever they are, and by classes in the same assembly.

(繼承來源 MethodBase)
IsFinal

取得值,指出這個方法是否為 finalGets a value indicating whether this method is final.

(繼承來源 MethodBase)
IsGenericMethod

取得值,指出目前的方法是否為泛型方法。Gets a value indicating whether the current method is a generic method.

IsGenericMethodDefinition

取得值,表示目前的 MethodInfo是否代表泛型方法的定義。Gets a value indicating whether the current MethodInfo represents the definition of a generic method.

IsHideBySig

取得值,指出是否只有簽章完全一樣的同類成員隱藏於衍生類別中。Gets a value indicating whether only a member of the same kind with exactly the same signature is hidden in the derived class.

(繼承來源 MethodBase)
IsPrivate

取得值,指出這個成員是否為私用的 (Private)。Gets a value indicating whether this member is private.

(繼承來源 MethodBase)
IsPublic

取得值,指出這是否為公用的方法。Gets a value indicating whether this is a public method.

(繼承來源 MethodBase)
IsSecurityCritical

取得值,這個值表示目前方法或建構函式在目前信任層級上是否為安全性關鍵或安全性安全關鍵,因而可以執行重要的作業。Gets a value that indicates whether the current method or constructor is security-critical or security-safe-critical at the current trust level, and therefore can perform critical operations.

(繼承來源 MethodBase)
IsSecuritySafeCritical

取得值,這個值表示目前方法或建構函式在目前信任層級上是否為安全性安全關鍵,也就是說,它是否可以執行重要作業並且可供透明程式碼存取。Gets a value that indicates whether the current method or constructor is security-safe-critical at the current trust level; that is, whether it can perform critical operations and can be accessed by transparent code.

(繼承來源 MethodBase)
IsSecurityTransparent

取得值,這個值表示目前方法或建構函式在目前信任層級上是否為透明,因此不得執行重要作業。Gets a value that indicates whether the current method or constructor is transparent at the current trust level, and therefore cannot perform critical operations.

(繼承來源 MethodBase)
IsSpecialName

取得值,指出這個方法是否有特別的名稱。Gets a value indicating whether this method has a special name.

(繼承來源 MethodBase)
IsStatic

取得值指出方法是否為 staticGets a value indicating whether the method is static.

(繼承來源 MethodBase)
IsVirtual

取得值指出方法是否為 virtualGets a value indicating whether the method is virtual.

(繼承來源 MethodBase)
MemberType

取得 MemberTypes 值,表示這個成員為方法。Gets a MemberTypes value indicating that this member is a method.

MetadataToken

取得值,這個值可識別中繼資料項目。Gets a value that identifies a metadata element.

(繼承來源 MemberInfo)
MethodHandle

取得方法內部中繼資料 (Metadata) 表示的控制代碼。Gets a handle to the internal metadata representation of a method.

(繼承來源 MethodBase)
MethodImplementationFlags

取得 MethodImplAttributes 旗標,這些旗標會指定方法實作的屬性。Gets the MethodImplAttributes flags that specify the attributes of a method implementation.

(繼承來源 MethodBase)
Module

取得用於定義型別的模組,該型別宣告以目前 MemberInfo 表示的成員。Gets the module in which the type that declares the member represented by the current MemberInfo is defined.

(繼承來源 MemberInfo)
Name

取得目前成員的名稱。Gets the name of the current member.

(繼承來源 MemberInfo)
ReflectedType

取得類別物件,是用來取得這個 MemberInfo 的執行個體。Gets the class object that was used to obtain this instance of MemberInfo.

(繼承來源 MemberInfo)
ReturnParameter

取得 ParameterInfo 物件,其中含有方法之傳回型別的相關資訊,例如傳回型別是否含有自訂修飾詞 (Modifier)。Gets a ParameterInfo object that contains information about the return type of the method, such as whether the return type has custom modifiers.

ReturnType

取得這個方法的傳回型別 (Return Type)。Gets the return type of this method.

ReturnTypeCustomAttributes

取得傳回型別的自訂屬性。Gets the custom attributes for the return type.

方法

CreateDelegate(Type)

從這個方法建立所指定類型的委派。Creates a delegate of the specified type from this method.

CreateDelegate(Type, Object)

從這個方法以指定的目標建立所指定類型的委派。Creates a delegate of the specified type with the specified target from this method.

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。Returns a value that indicates whether this instance is equal to a specified object.

GetBaseDefinition()

在衍生類別中覆寫時,為直接或間接基底類別 (也就是這個執行個體所代表的方法第一次被宣告的地方) 中的方法傳回 MethodInfo 物件。When overridden in a derived class, returns the MethodInfo object for the method on the direct or indirect base class in which the method represented by this instance was first declared.

GetCustomAttributes(Boolean)

在衍生類別中覆寫時,傳回套用至此成員之所有自訂屬性的陣列。When overridden in a derived class, returns an array of all custom attributes applied to this member.

(繼承來源 MemberInfo)
GetCustomAttributes(Type, Boolean)

當在衍生的類別中覆寫時,會傳回套用至這個成員的自訂屬性陣列,並以 Type 識別。When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type.

(繼承來源 MemberInfo)
GetCustomAttributesData()

傳回 CustomAttributeData 物件的清單,表示已套用至目標成員之屬性的資料。Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.

(繼承來源 MemberInfo)
GetGenericArguments()

傳回 Type 物件的陣列,這些物件代表泛型方法的類型引數,或泛型方法定義的類型參數。Returns an array of Type objects that represent the type arguments of a generic method or the type parameters of a generic method definition.

GetGenericMethodDefinition()

傳回表示泛型方法定義的 MethodInfo 物件,利用此泛型方法定義就可以建構出目前的方法。Returns a MethodInfo object that represents a generic method definition from which the current method can be constructed.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetMethodBody()

在衍生類別中覆寫時,取得 MethodBody 物件,其提供對目前方法之 MSIL 資料流、區域變數和例外狀況的存取。When overridden in a derived class, gets a MethodBody object that provides access to the MSIL stream, local variables, and exceptions for the current method.

(繼承來源 MethodBase)
GetMethodImplementationFlags()

在衍生類別中覆寫時,傳回 MethodImplAttributes 旗標。When overridden in a derived class, returns the MethodImplAttributes flags.

(繼承來源 MethodBase)
GetParameters()

在衍生類別中覆寫時,取得指定方法或建構函式的參數。When overridden in a derived class, gets the parameters of the specified method or constructor.

(繼承來源 MethodBase)
GetType()
HasSameMetadataDefinitionAs(MemberInfo) (繼承來源 MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

在衍生類別中覆寫時,需使用指定的參數叫用反映的方法或建構函式。When overridden in a derived class, invokes the reflected method or constructor with the given parameters.

(繼承來源 MethodBase)
Invoke(Object, Object[])
IsDefined(Type, Boolean)

在衍生類別中覆寫時,表示是否已有一個或多個具有指定型別或其衍生型別的屬性套用至這個成員。When overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member.

(繼承來源 MemberInfo)
MakeGenericMethod(Type[])

使用類型陣列的項目取代目前泛型方法定義的類型參數,並傳回代表所產生之建構方法的 MethodInfo 物件。Substitutes the elements of an array of types for the type parameters of the current generic method definition, and returns a MethodInfo object representing the resulting constructed method.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

運算子

Equality(MethodInfo, MethodInfo)

表示兩個 MethodInfo 物件是否相等。Indicates whether two MethodInfo objects are equal.

Inequality(MethodInfo, MethodInfo)

表示兩個 MethodInfo 物件是否不相等。Indicates whether two MethodInfo objects are not equal.

明確介面實作

_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(繼承來源 MemberInfo)
_MemberInfo.GetType()

取得 Type 物件,表示 MemberInfo 類別。Gets a Type object representing the MemberInfo class.

(繼承來源 MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can then be used to get the type information for an interface.

(繼承來源 MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(繼承來源 MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(繼承來源 MethodBase)
_MethodBase.GetType()

如需這個成員的說明,請參閱 GetType()For a description of this member, see GetType().

(繼承來源 MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can then be used to get the type information for an interface.

(繼承來源 MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(繼承來源 MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 MethodBase)
_MethodBase.IsAbstract

如需這個成員的說明,請參閱 IsAbstractFor a description of this member, see IsAbstract.

(繼承來源 MethodBase)
_MethodBase.IsAssembly

如需這個成員的說明,請參閱 IsAssemblyFor a description of this member, see IsAssembly.

(繼承來源 MethodBase)
_MethodBase.IsConstructor

如需這個成員的說明,請參閱 IsConstructorFor a description of this member, see IsConstructor.

(繼承來源 MethodBase)
_MethodBase.IsFamily

如需這個成員的說明,請參閱 IsFamilyFor a description of this member, see IsFamily.

(繼承來源 MethodBase)
_MethodBase.IsFamilyAndAssembly

如需這個成員的說明,請參閱 IsFamilyAndAssemblyFor a description of this member, see IsFamilyAndAssembly.

(繼承來源 MethodBase)
_MethodBase.IsFamilyOrAssembly

如需這個成員的說明,請參閱 IsFamilyOrAssemblyFor a description of this member, see IsFamilyOrAssembly.

(繼承來源 MethodBase)
_MethodBase.IsFinal

如需這個成員的說明,請參閱 IsFinalFor a description of this member, see IsFinal.

(繼承來源 MethodBase)
_MethodBase.IsHideBySig

如需這個成員的說明,請參閱 IsHideBySigFor a description of this member, see IsHideBySig.

(繼承來源 MethodBase)
_MethodBase.IsPrivate

如需這個成員的說明,請參閱 IsPrivateFor a description of this member, see IsPrivate.

(繼承來源 MethodBase)
_MethodBase.IsPublic

如需這個成員的說明,請參閱 IsPublicFor a description of this member, see IsPublic.

(繼承來源 MethodBase)
_MethodBase.IsSpecialName

如需這個成員的說明,請參閱 IsSpecialNameFor a description of this member, see IsSpecialName.

(繼承來源 MethodBase)
_MethodBase.IsStatic

如需這個成員的說明,請參閱 IsStaticFor a description of this member, see IsStatic.

(繼承來源 MethodBase)
_MethodBase.IsVirtual

如需這個成員的說明,請參閱 IsVirtualFor a description of this member, see IsVirtual.

(繼承來源 MethodBase)
_MethodInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

_MethodInfo.GetType()

提供 COM 之 GetType() 方法的存取。Provides access to the GetType() method from COM.

_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

_MethodInfo.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

ICustomAttributeProvider.GetCustomAttributes(Boolean) (繼承來源 MemberInfo)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean) (繼承來源 MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean) (繼承來源 MemberInfo)

擴充方法

GetCustomAttribute(MemberInfo, Type)

擷取指定型別的自訂屬性,此屬性套用至指定成員。Retrieves a custom attribute of a specified type that is applied to a specified member.

GetCustomAttribute(MemberInfo, Type, Boolean)

擷取只訂型別的自訂屬性,此屬性套用至指定成員,並且可選擇性檢查該成員的祖系。Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.

GetCustomAttribute<T>(MemberInfo)

擷取指定型別的自訂屬性,此屬性套用至指定成員。Retrieves a custom attribute of a specified type that is applied to a specified member.

GetCustomAttribute<T>(MemberInfo, Boolean)

擷取只訂型別的自訂屬性,此屬性套用至指定成員,並且可選擇性檢查該成員的祖系。Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.

GetCustomAttributes(MemberInfo)

擷取套用至指定成員的自訂屬性集合。Retrieves a collection of custom attributes that are applied to a specified member.

GetCustomAttributes(MemberInfo, Boolean)

擷取自訂屬性集合,此集合套用至指定成員,並且可選擇性檢查該成員的祖系。Retrieves a collection of custom attributes that are applied to a specified member, and optionally inspects the ancestors of that member.

GetCustomAttributes(MemberInfo, Type)

擷取指定型別的自訂屬性集合,此集合套用至指定成員。Retrieves a collection of custom attributes of a specified type that are applied to a specified member.

GetCustomAttributes(MemberInfo, Type, Boolean)

擷取指定型別的自訂屬性集合,此集合套用至指定成員,並且可選擇性檢查該成員的祖系。Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member.

GetCustomAttributes<T>(MemberInfo)

擷取指定型別的自訂屬性集合,此集合套用至指定成員。Retrieves a collection of custom attributes of a specified type that are applied to a specified member.

GetCustomAttributes<T>(MemberInfo, Boolean)

擷取指定型別的自訂屬性集合,此集合套用至指定成員,並且可選擇性檢查該成員的祖系。Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member.

IsDefined(MemberInfo, Type)

指出是否將所指定型別的自訂屬性套用至指定的成員。Indicates whether custom attributes of a specified type are applied to a specified member.

IsDefined(MemberInfo, Type, Boolean)

指出指定之型別的自訂屬性是否會套用至指定的成員,以及選擇性地套用到其上階。Indicates whether custom attributes of a specified type are applied to a specified member, and, optionally, applied to its ancestors.

GetMetadataToken(MemberInfo)

取得指定成員的中繼資料語彙基元 (如果有)。Gets a metadata token for the given member, if available.

HasMetadataToken(MemberInfo)

傳回值,指出所指定成員是否有可用的中繼資料語彙基元。Returns a value that indicates whether a metadata token is available for the specified member.

GetBaseDefinition(MethodInfo)
GetRuntimeBaseDefinition(MethodInfo)

擷取物件,表示直接或間接基底類別上的指定方法 (在這個類別上首次宣告這個方法)。Retrieves an object that represents the specified method on the direct or indirect base class where the method was first declared.

安全性

InheritanceDemand
適用於繼承者的完全信任的。for full trust for inheritors. 此類別無法由部分信任程式碼繼承。This class cannot be inherited by partially trusted code.

適用於

執行緒安全性

此型別具備執行緒安全。This type is thread safe.

另請參閱