BindingFlags

BindingFlags

These BindingFlags control binding for a great many classes in the System, System.Reflection, and System.Runtime namespaces that invoke, create, get, set, and find members and types.
The binding flags can be categorized by how they identify a type member, as listed in the following table.
Identified by Accessibility
Instance(实例成员), Static(静态成员)
NonPublic, Public

DeclaredOnly :指定只应考虑在所提供类型的层次结构级别上声明的成员。不考虑继承成员。例如Object类有toString()等方法,但是,当你使用Dog(extends Object)获取Public的Method时,如果不指定DeclaredOnly,Object中定义的这些方法也会返回,否则就不返回;
FlattenHierarchy : 继承树上层的Public 或 Protected Static成员也会返回,如果不指定就不会返回;看代码的例子
IgnoreCase:指定当绑定时不应考虑成员名的大小写;
IgnoreReturn:在 COM interop 中用于指定可以忽略成员的返回值;

ContractedBlock.gifExpandedBlockStart.gifFlattenHierarchy
 1     class A : B
 2     {
 3     }
 4 
 5     class B
 6     {
 7         public static void Foo(int b)
 8         {
 9             Console.WriteLine("From B");
10 
11         }
12     }
13 
14 typeof(A).GetMethod("Foo",System.Reflection.BindingFlags.Static| System.Reflection.BindingFlags.Public)
15 null
16 typeof(A).GetMethod("Foo",System.Reflection.BindingFlags.Static| System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.FlattenHierarchy)
17 {Void Foo(Int32)}
18     [System.Reflection.RuntimeMethodInfo]: {Void Foo(Int32)}
19     base {System.Reflection.MethodBase}: {Void Foo(Int32)}
20     ContainsGenericParameters: false
21     IsGenericMethod: false
22     IsGenericMethodDefinition: false
23     MemberType: Method
24     ReturnParameter: {Void }
25     ReturnType: {Name = "Void" FullName = "System.Void"}
26     ReturnTypeCustomAttributes: {Void }
27 

Identified by Binding Argument


ExactBinding :Specifies that types of the supplied arguments must exactly match the types of the corresponding formal parameters.
OptionalParamBinding : 返回其参数计数与提供参数的数目匹配的成员集。此绑定标志用于所带参数具有默认值的方法和带变量参数 (varargs) 的方法。此标志应只与 Type.InvokeMember 一起使用;

Identified by Operation(这部分功能与)

CreateInstance :
GetField :
SetField :
GetProperty :
SetProperty :
InvokeMethod:
PutDispProperty :
PutRefDispProperty :


 

转载于:https://www.cnblogs.com/whyandinside/archive/2009/08/28/1555975.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值