本文整理汇总了C#中System.Reflection.Binder.BindToField方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.BindToField方法的具体用法?C# Binder.BindToField怎么用?C# Binder.BindToField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Binder
的用法示例。
在下文中一共展示了Binder.BindToField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeMember
//.........这里部分代码省略.........
if ((invokeAttr & BindingFlags.GetField) != 0 ||
(invokeAttr & BindingFlags.SetField) != 0) {
FieldInfo[] flds=null;
// validate the set/get stuff
if (((invokeAttr & (BindingFlags) BinderGetSetField) ^ (BindingFlags) BinderGetSetField) == 0)
throw new ArgumentException(Environment.GetResourceString("Arg_FldSetGet"),"invokeAttr");
if (((invokeAttr & (BindingFlags) BinderSetInvokeField) ^ (BindingFlags)BinderSetInvokeField) == 0)
throw new ArgumentException(Environment.GetResourceString("Arg_FldSetInvoke"),"invokeAttr");
bool fieldGet = ((invokeAttr & BindingFlags.GetField) != 0);
if (fieldGet) {
if ((invokeAttr & BindingFlags.SetProperty) != 0)
throw new ArgumentException(Environment.GetResourceString("Arg_FldGetPropSet"),"invokeAttr");
}
else {
if ((invokeAttr & BindingFlags.GetProperty) != 0)
throw new ArgumentException(Environment.GetResourceString("Arg_FldSetPropGet"),"invokeAttr");
}
flds = GetMemberField(name,invokeAttr, false);
// We are only doing a field/set get
if (flds != null) {
if (flds.Length != 1) {
Object o;
if (fieldGet)
o = Empty.Value;
else {
if (args == null)
throw new ArgumentNullException("args");
o = args[0];
}
selFld = binder.BindToField(invokeAttr,flds,o,culture);
}
else {
selFld = flds[0];
}
}
// If we are only set/get field we leave here with errors...
if ((invokeAttr & (BindingFlags) BinderNonFieldGetSet) == 0) {
if (flds == null)
throw new MissingFieldException(FullName, name);
if (flds.Length == 1)
selFld = flds[0];
else
if (selFld == null)
throw new MissingFieldException(FullName, name);
}
// If we can continue we leave if we found a field. Fields
// now have the highest priority.
if (selFld != null) {
//Console.WriteLine(selFld.FieldType.Name);
//Console.WriteLine("argCnt:" + argCnt);
// For arrays we are going to see if they are trying to access the array
if (selFld.FieldType.IsArray || selFld.FieldType == typeof(System.Array)) {
int idxCnt;
if ((invokeAttr & BindingFlags.GetField) != 0) {
idxCnt = argCnt;
}
else {
idxCnt = argCnt - 1;