当前位置: 首页>>代码示例>>C#>>正文


C# Expression.AsEnumerable方法代码示例

本文整理汇总了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());
            }
        }
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:60,代码来源:ConditionalIndexTests.cs

示例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());
            }
        }
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:44,代码来源:ConditionalInvokeTests.cs


注:本文中的System.Linq.Expressions.Expression.AsEnumerable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。