本文整理汇总了C#中MethodBase.Where方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.Where方法的具体用法?C# MethodBase.Where怎么用?C# MethodBase.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodBase
的用法示例。
在下文中一共展示了MethodBase.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectMethod
public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
{
MethodBase[] methodCandidates;
this.SelectMethodCalled = true;
if (this.genericTypeArguments.Length > 0)
{
// Accept only generic methods which can be successfully instantiated w/ these parameters
Collection<MethodBase> methods = new Collection<MethodBase>();
foreach (MethodBase method in match)
{
// Must be a MethodInfo because we've already filtered out constructors
MethodInfo instantiatedMethod = Instantiate((MethodInfo)method, this.genericTypeArguments);
if (instantiatedMethod != null)
{
methods.Add(instantiatedMethod);
}
}
methodCandidates = methods.ToArray();
}
else
{
// Accept only candidates which are already instantiated
methodCandidates = match.Where(m => m.ContainsGenericParameters == false).ToArray();
}
if (methodCandidates.Length == 0)
{
return null;
}
// Methods declared on this.declaringType class get top priority as matches
Type declaringType = this.declaringType;
MethodBase result = null;
do
{
MethodBase[] methodsDeclaredHere = methodCandidates.Where(mb => mb.DeclaringType == declaringType).ToArray();
if (methodsDeclaredHere.Length > 0)
{
// Try to find a match
result = FindMatch(methodsDeclaredHere, bindingAttr, types, modifiers);
}
declaringType = declaringType.BaseType;
}
while (declaringType != null && result == null); // short-circuit as soon as we find a match
return result; // returns null if no match found
}