本文整理汇总了C#中System.Collections.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.AddRange方法的具体用法?C# System.Collections.AddRange怎么用?C# System.Collections.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections
的用法示例。
在下文中一共展示了System.Collections.AddRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
var instanceType = node.Object == null ? null : node.Object.Type;
var map = new[] { new { Param = instanceType, Arg = node.Object } }.ToList();
map.AddRange(node.Method.GetParameters()
.Zip(node.Arguments, (p, a) => new { Param = p.ParameterType, Arg = a }));
// for any local collection parameters in the method, make a
// replacement argument which will print its elements
var replacements = (map.Where(x => x.Param != null && x.Param.IsGenericType)
.Select(x => new {x, g = x.Param.GetGenericTypeDefinition()})
.Where(@t => @t.g == typeof (IEnumerable<>) || @t.g == typeof (List<>))
.Where(@t => @t.x.Arg.NodeType == ExpressionType.Constant)
.Select(@t => new {@t, elementType = @t.x.Param.GetGenericArguments().Single()})
.Select(
@t =>
new
{
@[email protected],
Replacement =
Expression.Constant("{" + string.Join("|", (IEnumerable) ((ConstantExpression) @[email protected]).Value) + "}")
})).ToList();
if (replacements.Any())
{
var args = map.Select(x => (from r in replacements
where r.Arg == x.Arg
select r.Replacement).SingleOrDefault() ?? x.Arg).ToList();
node = node.Update(args.First(), args.Skip(1));
}
return base.VisitMethodCall(node);
}