本文整理汇总了C#中System.Arguments.FilteredFor方法的典型用法代码示例。如果您正苦于以下问题:C# Arguments.FilteredFor方法的具体用法?C# Arguments.FilteredFor怎么用?C# Arguments.FilteredFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Arguments
的用法示例。
在下文中一共展示了Arguments.FilteredFor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBestMatch
ConstructorData GetBestMatch(IEnumerable<ConstructorInfo> constructors, Arguments args, Dictionary<ConstructorInfo, IList<ParameterInfo>> unresolved)
{
var ctors = constructors.Select(c => new ConstructorMatchData
{
Constructor = c,
Parameters = c.GetParameters().ToList(),
ParameterDelta = c.GetParameters().Count() - args.Count(), /* negative number here is most likely (and wanted!) */
MatchLength = 0,
Score = 0
});
foreach (var ctor in ctors)
{
for (var i = 0; i < Math.Min(ctor.Parameters.Count(), args.Count()); i++)
{
if (ctor.Parameters[i].Name != args[i].Name || ctor.Parameters[i].ParameterType != args[i].Value.GetType())
{
break;
}
ctor.MatchLength = ctor.MatchLength + 1;
}
}
foreach (var ctor in ctors)
{
ctor.Score = ctor.MatchLength + ctor.ParameterDelta;
}
//check if the top item has a unique score
var best = ctors.Where(c => c.Score == ctors.OrderBy(t => t.Score).First().Score);
if (best.Count() == 1)
{
return new ConstructorData(best.First().Constructor, args.FilteredFor(best.First().Constructor));
}
//apply the delta again to try and distinct the matches
foreach (var ctor in ctors)
{
ctor.Score += ctor.ParameterDelta;
}
//check if the top item has a unique score
best = ctors.Where(c => c.Score == ctors.OrderBy(t => t.Score).First().Score);
if (best.Count() == 1)
{
return new ConstructorData(best.First().Constructor, args.FilteredFor(best.First().Constructor));
}
throw new ConstructorException();
}