本文整理汇总了C#中System.Reflection.MethodBase.Where方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.Where方法的具体用法?C# MethodBase.Where怎么用?C# MethodBase.Where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.Where方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterMethodBases
private static MethodBase FilterMethodBases(MethodBase[] methodBases, Type[] parameterTypes, string methodName)
{
if (methodBases == null || string.IsNullOrEmpty(methodName))
return null;
var matchedMethods = methodBases.Where(method => method.Name.Equals(methodName));
matchedMethods = matchedMethods.Where(method => TypeSequenceEqual(method.GetParameters().Select(param => param.ParameterType).ToArray(), parameterTypes));
return matchedMethods.FirstOrDefault();
}
示例2: FindBestMatch
public static IEnumerable<MethodBase> FindBestMatch(Engine engine, MethodBase[] methods, JsValue[] arguments)
{
methods = methods
.Where(m => m.GetParameters().Count() == arguments.Length ||
(m.IsGenericMethodDefinition && m.GetGenericArguments().Count() == arguments.Length))
.ToArray();
if (methods.Length == 1 && !methods[0].GetParameters().Any())
{
yield return methods[0];
yield break;
}
var objectArguments = arguments.Select(x => x.ToObject()).ToArray();
foreach (var method in methods)
{
var perfectMatch = true;
var parameters = method.GetParameters();
for (var i = 0; i < arguments.Length; i++)
{
var arg = objectArguments[i];
var paramType = parameters[i].ParameterType;
if (arg == null)
{
if (!TypeIsNullable(paramType))
{
perfectMatch = false;
break;
}
}
else if (arg.GetType() != paramType)
{
perfectMatch = false;
break;
}
}
if (perfectMatch)
{
yield return method;
yield break;
}
}
foreach (var method in methods)
{
yield return method;
}
}
示例3: BindToMethod
public static MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, string[] names, out Object state)
{
//TODO: implement entirely
state = null;
var theArgs = args;
var validMatches = match.Where(m => CanBind(m, theArgs)).ToArray();
switch (validMatches.Length)
{
case 1:
return validMatches[0];
case 0:
throw new MissingMethodException();
default:
throw new AmbiguousMatchException();
}
}
示例4: FindBestMatch
public static IEnumerable<MethodBase> FindBestMatch(Engine engine, MethodBase[] methods, JsValue[] arguments)
{
methods = methods
.Where(m => m.GetParameters().Count() == arguments.Length)
.ToArray()
;
if (methods.Length == 1 && !methods[0].GetParameters().Any())
{
yield return methods[0];
yield break;
}
var objectArguments = arguments.Select(x => x.ToObject()).ToArray();
foreach (var method in methods)
{
var perfectMatch = true;
var parameters = method.GetParameters();
for (var i = 0; i < arguments.Length; i++)
{
if (objectArguments[i].GetType() != parameters[i].ParameterType)
{
perfectMatch = false;
break;
}
}
if (perfectMatch)
{
yield return method;
yield break;
}
}
var candidates = new List<MethodBase>();
foreach (var method in methods)
{
var parameters = new object[arguments.Length];
try
{
for (var i = 0; i < arguments.Length; i++)
{
parameters[i] = engine.Options.GetTypeConverter().Convert(
arguments[i].ToObject(),
method.GetParameters()[i].ParameterType,
CultureInfo.InvariantCulture);
}
}
catch
{
// ignore method
}
candidates.Add(method);
}
foreach (var candidate in candidates)
yield return candidate;
}