本文整理汇总了C#中Binder.BindToMethod方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.BindToMethod方法的具体用法?C# Binder.BindToMethod怎么用?C# Binder.BindToMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binder
的用法示例。
在下文中一共展示了Binder.BindToMethod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeMember
//.........这里部分代码省略.........
if (finalist == null && isGetProperty || isSetProperty)
{
#region Lookup Property
PropertyInfo[] semiFinalists = GetMember(name, MemberTypes.Property, bindingFlags) as PropertyInfo[];
LowLevelListWithIList<MethodInfo> results = null;
for (int i = 0; i < semiFinalists.Length; i++)
{
MethodInfo semiFinalist = null;
if (isSetProperty)
{
semiFinalist = semiFinalists[i].GetSetMethod(true);
}
else
{
semiFinalist = semiFinalists[i].GetGetMethod(true);
}
if (semiFinalist == null)
continue;
BindingFlags expectedBindingFlags = semiFinalist.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
if ((bindingFlags & expectedBindingFlags) != expectedBindingFlags)
continue;
if (!semiFinalist.QualifiesBasedOnParameterCount(bindingFlags, CallingConventions.Any, new Type[argCnt]))
continue;
if (finalist == null)
{
finalist = semiFinalist;
}
else
{
if (results == null)
{
results = new LowLevelListWithIList<MethodInfo>(semiFinalists.Length);
results.Add(finalist);
}
results.Add(semiFinalist);
}
}
if (results != null)
{
Debug.Assert(results.Count > 1);
finalists = new MethodInfo[results.Count];
results.CopyTo(finalists, 0);
}
#endregion
}
#endregion
if (finalist != null)
{
#region Invoke
if (finalists == null &&
argCnt == 0 &&
finalist.GetParametersNoCopy().Length == 0 &&
(bindingFlags & BindingFlags.OptionalParamBinding) == 0)
{
//if (useCache && argCnt == props[0].GetParameters().Length)
// AddMethodToCache(name, bindingFlags, argCnt, providedArgs, props[0]);
return finalist.Invoke(target, bindingFlags, binder, providedArgs, culture);
}
if (finalists == null)
finalists = new MethodInfo[] { finalist };
if (providedArgs == null)
providedArgs = Array.Empty<object>();
Object state = null;
MethodBase invokeMethod = null;
try { invokeMethod = binder.BindToMethod(bindingFlags, finalists, ref providedArgs, modifiers, culture, namedParams, out state); }
catch (MissingMethodException) { }
if (invokeMethod == null)
throw new MissingMethodException(FullName, name);
//if (useCache && argCnt == invokeMethod.GetParameters().Length)
// AddMethodToCache(name, bindingFlags, argCnt, providedArgs, invokeMethod);
Object result = ((MethodInfo)invokeMethod).Invoke(target, bindingFlags, binder, providedArgs, culture);
if (state != null)
binder.ReorderArgumentArray(ref providedArgs, state);
return result;
#endregion
}
throw new MissingMethodException(FullName, name);
}