當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。