本文整理匯總了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());
}
}