本文整理汇总了C#中Jint.Native.JsValue.Select方法的典型用法代码示例。如果您正苦于以下问题:C# JsValue.Select方法的具体用法?C# JsValue.Select怎么用?C# JsValue.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Native.JsValue
的用法示例。
在下文中一共展示了JsValue.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: 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;
}