本文整理汇总了C#中System.Linq.Expressions.Expression.AsEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.AsEnumerable方法的具体用法?C# Expression.AsEnumerable怎么用?C# Expression.AsEnumerable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.AsEnumerable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConditionalIndex_Factory_Expression
public void ConditionalIndex_Factory_Expression()
{
var obj = Expression.Constant(new S("foo"));
var substring = PropertyInfoOf((S s) => s[default(int), default(int)]);
var substringGet = substring.GetGetMethod(true);
var args = new[] { Expression.Constant(1) };
foreach (var e in new[]
{
CSharpExpression.ConditionalIndex(obj, substring, args),
CSharpExpression.ConditionalIndex(obj, substring, args.AsEnumerable()),
})
{
Assert.AreSame(obj, e.Object);
Assert.AreEqual(1, e.Arguments.Count);
Assert.AreEqual(substring.GetIndexParameters()[0], e.Arguments[0].Parameter);
Assert.AreSame(args[0], e.Arguments[0].Expression);
}
foreach (var e in new[]
{
CSharpExpression.ConditionalIndex(obj, substringGet, args),
CSharpExpression.ConditionalIndex(obj, substringGet, args.AsEnumerable()),
})
{
Assert.AreSame(obj, e.Object);
Assert.AreEqual(1, e.Arguments.Count);
Assert.AreEqual(substringGet.GetParameters()[0], e.Arguments[0].Parameter);
Assert.AreSame(args[0], e.Arguments[0].Expression);
}
var tooLittle = new Expression[0];
foreach (var f in new Func<ConditionalIndexCSharpExpression>[]
{
() => CSharpExpression.ConditionalIndex(obj, substring, tooLittle),
() => CSharpExpression.ConditionalIndex(obj, substring, tooLittle.AsEnumerable()),
})
{
AssertEx.Throws<ArgumentException>(() => f());
}
var tooMany = new[] { Expression.Constant(1), Expression.Constant(2), Expression.Constant(3) };
foreach (var f in new Func<ConditionalIndexCSharpExpression>[]
{
() => CSharpExpression.ConditionalIndex(obj, substring, tooMany),
() => CSharpExpression.ConditionalIndex(obj, substring, tooMany.AsEnumerable()),
})
{
AssertEx.Throws<ArgumentException>(() => f());
}
}
示例2: ConditionalInvoke_Factory_Expression
public void ConditionalInvoke_Factory_Expression()
{
var function = Expression.Constant(new D((x, y) => x + y));
var method = typeof(D).GetMethod("Invoke");
var args = new[] { Expression.Constant(1) };
foreach (var e in new[]
{
CSharpExpression.ConditionalInvoke(function, args),
CSharpExpression.ConditionalInvoke(function, args.AsEnumerable()),
})
{
Assert.AreSame(function, e.Expression);
Assert.AreEqual(1, e.Arguments.Count);
Assert.AreEqual(method.GetParameters()[0], e.Arguments[0].Parameter);
Assert.AreSame(args[0], e.Arguments[0].Expression);
}
var tooLittle = new Expression[0];
foreach (var f in new Func<ConditionalInvocationCSharpExpression>[]
{
() => CSharpExpression.ConditionalInvoke(function, tooLittle),
() => CSharpExpression.ConditionalInvoke(function, tooLittle.AsEnumerable()),
})
{
AssertEx.Throws<ArgumentException>(() => f());
}
var tooMany = new[] { Expression.Constant(1), Expression.Constant(2), Expression.Constant(3) };
foreach (var f in new Func<ConditionalInvocationCSharpExpression>[]
{
() => CSharpExpression.ConditionalInvoke(function, tooMany),
() => CSharpExpression.ConditionalInvoke(function, tooMany.AsEnumerable()),
})
{
AssertEx.Throws<ArgumentException>(() => f());
}
}