您的位置:首页 > 编程语言 > C#

C#学习常用命名空间【1000】---System.Reflection 之MethodInfo(方法信息类)

2016-12-06 11:43 781 查看

MethodInfo 类

发现方法的属性并提供对方法元数据的访问。
命名空间:
System.Reflection
程序集: mscorlib(位于 mscorlib.dll)

继承层次结构
System.Object
System.Reflection.MemberInfo
System.Reflection.MethodBase
System.Reflection.MethodInfo
Microsoft.JScript.JSMethod
Microsoft.JScript.JSMethodInfo
System.Reflection.Emit.DynamicMethod
System.Reflection.Emit.MethodBuilder
语法:
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class MethodInfo : MethodBase, _MethodInfo
(emit:发出,发表)

构造函数
名称说明

MethodInfo()初始化 MethodInfo 类的新实例。

属性
名称说明

Attributes获取与此方法关联的属性。(继承自 MethodBase。)

CallingConvention获取一个值,该值指示此方法的调用约定。(继承自 MethodBase。)

ContainsGenericParameters获取一个值,该值指示泛型方法是否包含未分配的泛型类型参数。(继承自 MethodBase。)

CustomAttributes获取包含此成员的自定义特性的集合。(继承自 MemberInfo。)

DeclaringType获取声明此成员的类。(继承自 MemberInfo。)

IsAbstract获取一个值,该值指示该方法为抽象。(继承自 MethodBase。)

IsAssembly获取一个值,该值指示是否由描述此方法或构造函数的潜在可见 MethodAttributes.Assembly; 也就是说,方法或构造函数显示最多为同一程序集中的其他类型也看不到派生类型的程序集之外。(继承自 MethodBase。)

IsConstructor获取一个值,该值指示方法是否一个构造函数。(继承自 MethodBase。)

IsFamily获取一个值,该值指示是否由描述此方法或构造函数的可见性 MethodAttributes.Family; 即方法或构造函数是仅在其类以及派生的类中可见。(继承自 MethodBase。)

IsFamilyAndAssembly获取一个值,该值指示是否由描述此方法或构造函数的可见性 MethodAttributes.FamANDAssem; 也就是说,方法或构造函数可由派生类中,但仅限它们是否位于同一程序集中。(继承自 MethodBase。)

IsFamilyOrAssembly获取一个值,该值指示是否由描述此方法或构造函数的潜在可见 MethodAttributes.FamORAssem; 也就是说,该方法或构造函数可以调用由派生类无论他们身在何处,并由同一程序集中的类。(继承自 MethodBase。)

IsFinal获取一个值,该值指示此方法是否 final。(继承自 MethodBase。)

IsGenericMethod获取一个值,该值指示该方法泛型。(继承自 MethodBase。)

IsGenericMethodDefinition获取一个值,该值指示方法是否泛型方法定义。(继承自 MethodBase。)

IsHideBySig获取一个值,该值指示是否在派生类中隐藏只有完全相同的签名的相同种类的成员。(继承自 MethodBase。)

IsPrivate获取一个值,该值指示此成员私有。(继承自 MethodBase。)

IsPublic获取一个值,该值指示这是否为公共方法。(继承自 MethodBase。)

IsSecurityCritical获取一个值,该值指示当前方法或构造函数是安全关键或安全可靠关键在当前信任级别,因此可以执行关键操作。(继承自 MethodBase。)

IsSecuritySafeCritical获取一个值,该值指示是否当前方法或构造函数是安全可靠关键在当前信任级别;也就是说,它是否可以执行关键操作并可以由透明代码访问。(继承自 MethodBase。)

IsSecurityTransparent获取一个值,该值指示是否当前方法或构造函数是在透明当前信任级别,并因此不能执行一些关键操作。(继承自 MethodBase。)

IsSpecialName获取一个值,该值指示此方法是否具有特殊名称。(继承自 MethodBase。)

IsStatic获取一个值,该值指示方法是否 static。(继承自 MethodBase。)

IsVirtual获取一个值,该值指示方法是否 virtual。(继承自 MethodBase。)

MemberType获取一个 MemberTypes 值,该值指示此成员是方法。(覆盖 MemberInfo.MemberType。)

MetadataToken获取一个值,标识元数据中的元素。(继承自 MemberInfo。)

MethodHandle获取一种方法的内部元数据表示的句柄。(继承自 MethodBase。)

MethodImplementationFlags获取 MethodImplAttributes 标志,用于指定某个方法实现的属性。(继承自 MethodBase。)

Module获取在其中声明该成员的类型表示由当前类型的模块 MemberInfo 定义。(继承自 MemberInfo。)

Name获取当前成员的名称。(继承自 MemberInfo。)

ReflectedType获取用于获取此实例的类对象 MemberInfo。(继承自 MemberInfo。)

ReturnParameter获取一个 ParameterInfo 对象,该对象包含有关方法的返回类型的信息(例如返回类型是否具有自定义修饰符)。

ReturnType获取此方法的返回类型。

ReturnTypeCustomAttributes获取返回类型的自定义属性。

方法
名称说明

CreateDelegate(Type)从此方法创建指定类型的委托。

CreateDelegate(Type,Object)从此方法创建具有指定目标的指定类型的委托。

Equals(Object)返回一个值,该值指示此实例是否与指定的对象相等。(覆盖 MethodBase.Equals(Object)。)

Finalize()在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(继承自 Object。)

GetBaseDefinition()当在派生类中被重写时,为直接或间接的基类(用该实例表示的方法首先在此类中声明)上的方法返回 MethodInfo 对象。

GetCustomAttributes(Boolean)当在派生类中重写,则返回的所有自定义特性应用于此成员的数组。(继承自 MemberInfo。)

GetCustomAttributes(Type,Boolean)当在派生类中重写时返回的自定义特性应用于此成员和由标识数组 Type。(继承自 MemberInfo。)

GetCustomAttributesData()返回的列表 CustomAttributeData 对象表示有关已应用于目标成员的特性的数据。(继承自 MemberInfo。)

GetGenericArguments()返回 Type 对象的数组,这些对象表示泛型方法的类型实参或泛型方法定义的类型形参。(覆盖 MethodBase.GetGenericArguments()。)

GetGenericMethodDefinition()返回一个 MethodInfo 对象,该对象表示可从其构造当前方法的泛型方法定义。

GetHashCode()返回此实例的哈希代码。(覆盖 MethodBase.GetHashCode()。)

GetMethodBody()当在派生类中重写时获取 MethodBody 对象,它提供访问当前方法的 MSIL 流、 本地变量和异常。(继承自 MethodBase。)

GetMethodImplementationFlags()当在派生类中重写返回 MethodImplAttributes 标志。(继承自 MethodBase。)

GetParameters()当在派生类中重写,获取指定的方法或构造函数的参数。(继承自 MethodBase。)

GetType()获取当前实例的 Type。(继承自 Object。)

Invoke(Object,BindingFlags,Binder,Object[],CultureInfo)当在派生类中重写时,将调用的反射的方法或使用给定的参数的构造函数。(继承自 MethodBase。)

Invoke(Object,Object[])调用方法或构造函数使用指定的参数与当前实例表示的。(继承自 MethodBase。)

IsDefined(Type,Boolean)当在派生类中重写,该值指示是否指定类型的字段或其派生类型的一个或多个特性应用于此成员。(继承自 MemberInfo。)

MakeGenericMethod(Type[])用类型数组的元素替代当前泛型方法定义的类型参数,并返回表示结果构造方法的 MethodInfo 对象。

MemberwiseClone()创建当前 Object 的浅表副本。(继承自 Object。)

ToString()返回表示当前对象的字符串。(继承自 Object。)

运算符
名称说明



Equality(MethodInfo,MethodInfo)指示两个 MethodInfo 对象是否相等。



Inequality(MethodInfo,MethodInfo)指示两个 MethodInfo 对象是否不相等。

显式接口实现
名称说明



_MemberInfo.GetIDsOfNames(Guid,IntPtr,UInt32,UInt32,IntPtr)将一组名称映射为对应的一组调度标识符。(继承自 MemberInfo。)



_MemberInfo.GetType()获取 Type 对象,表示 MemberInfo 类。(继承自 MemberInfo。)



_MemberInfo.GetTypeInfo(UInt32,UInt32,IntPtr)检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 MemberInfo。)



_MemberInfo.GetTypeInfoCount(UInt32)检索对象提供的类型信息接口的数量(0 或 1)。(继承自 MemberInfo。)



_MemberInfo.Invoke(UInt32,Guid,UInt32,Int16,IntPtr,IntPtr,IntPtr,IntPtr)提供对某一对象公开的属性和方法的访问。(继承自 MemberInfo。)



_MethodBase.GetIDsOfNames(Guid,IntPtr,UInt32,UInt32,IntPtr)将一组名称映射为对应的一组调度标识符。(继承自 MethodBase。)



_MethodBase.GetType()有关此成员的说明,请参阅 _MethodBase.GetType。(继承自 MethodBase。)



_MethodBase.GetTypeInfo(UInt32,UInt32,IntPtr)检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 MethodBase。)



_MethodBase.GetTypeInfoCount(UInt32)检索对象提供的类型信息接口的数量(0 或 1)。(继承自 MethodBase。)



_MethodBase.Invoke(UInt32,Guid,UInt32,Int16,IntPtr,IntPtr,IntPtr,IntPtr)提供对某一对象公开的属性和方法的访问。(继承自 MethodBase。)



_MethodInfo.GetIDsOfNames(Guid,IntPtr,UInt32,UInt32,IntPtr)将一组名称映射为对应的一组调度标识符。



_MethodInfo.GetType()提供从 COM 对 GetType 方法的访问。



_MethodInfo.GetTypeInfo(UInt32,UInt32,IntPtr)检索对象的类型信息,然后可以使用该信息获取接口的类型信息。



_MethodInfo.GetTypeInfoCount(UInt32)检索对象提供的类型信息接口的数量(0 或 1)。



_MethodInfo.Invoke(UInt32,Guid,UInt32,Int16,IntPtr,IntPtr,IntPtr,IntPtr)提供对某一对象公开的属性和方法的访问。



_MethodBase.IsAbstract有关此成员的说明,请参阅 _MethodBase.IsAbstract。(继承自 MethodBase。)



_MethodBase.IsAssembly有关此成员的说明,请参阅 _MethodBase.IsAssembly。(继承自 MethodBase。)



_MethodBase.IsConstructor有关此成员的说明,请参阅 _MethodBase.IsConstructor。(继承自 MethodBase。)



_MethodBase.IsFamily有关此成员的说明,请参阅 _MethodBase.IsFamily。(继承自 MethodBase。)



_MethodBase.IsFamilyAndAssembly有关此成员的说明,请参阅 _MethodBase.IsFamilyAndAssembly。(继承自 MethodBase。)



_MethodBase.IsFamilyOrAssembly有关此成员的说明,请参阅 _MethodBase.IsFamilyOrAssembly。(继承自 MethodBase。)



_MethodBase.IsFinal有关此成员的说明,请参阅 _MethodBase.IsFinal。(继承自 MethodBase。)



_MethodBase.IsHideBySig有关此成员的说明,请参阅 _MethodBase.IsHideBySig。(继承自 MethodBase。)



_MethodBase.IsPrivate有关此成员的说明,请参阅 _MethodBase.IsPrivate。(继承自 MethodBase。)



_MethodBase.IsPublic有关此成员的说明,请参阅 _MethodBase.IsPublic。(继承自 MethodBase。)



_MethodBase.IsSpecialName有关此成员的说明,请参阅 _MethodBase.IsSpecialName。(继承自 MethodBase。)



_MethodBase.IsStatic有关此成员的说明,请参阅 _MethodBase.IsStatic。(继承自 MethodBase。)



_MethodBase.IsVirtual有关此成员的说明,请参阅 _MethodBase.IsVirtual。(继承自 MethodBase。)

扩展方法
名称说明

GetCustomAttribute(Type)已重载。检索指定类型的应用于指定的成员的自定义属性。(由 CustomAttributeExtensions 定义。)

GetCustomAttribute(Type,Boolean)已重载。检索指定类型的应用于指定的成员,并根据需要检查该成员的祖先的自定义属性。(由 CustomAttributeExtensions 定义。)

GetCustomAttribute<T>()已重载。检索指定类型的应用于指定的成员的自定义属性。(由 CustomAttributeExtensions 定义。)

GetCustomAttribute<T>(Boolean)已重载。检索指定类型的应用于指定的成员,并根据需要检查该成员的祖先的自定义属性。(由 CustomAttributeExtensions 定义。)

GetCustomAttributes()已重载。检索应用于指定的成员的自定义特性的集合。(由 CustomAttributeExtensions 定义。)

GetCustomAttributes(Type)已重载。检索具有指定类型的自定义应用于指定的成员的特性的集合。(由 CustomAttributeExtensions 定义。)

GetCustomAttributes<T>(Boolean)已重载。检索应用于指定成员的自定义特性的指定类型的集合,并根据需要检查该成员的祖先。(由 CustomAttributeExtensions 定义。)

GetRuntimeBaseDefinition()检索表示直接或间接基类首先声明该方法的位置上的指定的方法的对象。(由 RuntimeReflectionExtensions 定义。)

IsDefined(Type)已重载。指示是否为指定类型的自定义特性随即应用于指定的成员。(由 CustomAttributeExtensions 定义。)

备注
MethodInfo 类表示一种类型的方法。 您可以使用 MethodInfo 对象来获取有关该对象表示方法的信息和调用方法。 例如:
您可以通过检索的值来确定该方法的可见性 IsFamilyAndAssembly, ,IsFamilyOrAssembly, ,IsPrivate, ,和 IsPublic 属性。

你可以发现哪些属性检索的值可以通过应用到该方法 Attributes 属性或调用 GetCustomAttributes方法。

该方法是泛型方法、 开放构造泛型方法,还是为封闭通过检索值的构造泛型方法,可以确定 IsGenericMethodContainsGenericParameters 属性。

你可以获取有关方法的参数的信息,并返回类型从 GetParameters 方法和 ReturnParameter, ,ReturnType, ,和 ReturnTypeCustomAttributes 属性。

可以对类实例执行的方法,通过调用 Invoke 方法。

您可以实例化 MethodInfo 对象,表示从一个通过调用表示泛型方法定义一个构造泛型方法 MakeGenericMethod 方法。

您可以实例化 MethodInfo 实例通过调用 Type.GetMethodsType.GetMethod 方法,或通过调用 MethodInfo.MakeGenericMethod 方法 MethodInfo 表示泛型方法定义的对象。
特定于泛型方法的术语的固定条件的列表,请参阅 IsGenericMethod 属性。 使用泛型反射中的其他术语的固定条件的列表,请参阅 IsGenericType 属性。

继承函数说明:

继承自 MethodInfo, ,必须重写 MethodInfo.GetBaseDefinition, ,MethodInfo.ReturnType, ,MethodInfo.ReturnTypeCustomAttributes, ,MethodBase.GetParameters, ,MethodBase.GetMethodImplementationFlags, ,MethodBase.MethodHandle, ,MethodBase.Attributes, ,MethodBase.Invoke, ,MemberInfo.Name, ,MemberInfo.MemberType, ,MemberInfo.DeclaringType, ,MemberInfo.ReflectedType, ,MemberInfo.GetCustomAttributes, ,MemberInfo.GetCustomAttributes, ,和 MemberInfo.IsDefined

安全性
SecurityAction.InheritanceDemand
for full trust for inheritors. This class cannot be inherited by partially trusted code.

备注:转自https://msdn.microsoft.com/zh-cn/library/system.reflection.methodinfo.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐