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


C# ExpressionGenerator.FromFunc方法代码示例

本文整理汇总了C#中ExpressionGenerator.FromFunc方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionGenerator.FromFunc方法的具体用法?C# ExpressionGenerator.FromFunc怎么用?C# ExpressionGenerator.FromFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExpressionGenerator的用法示例。


在下文中一共展示了ExpressionGenerator.FromFunc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test007

        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new string[] { "A", "B", "C", "D" });
            var expr2 = xgr.FromFunc(() => new string[] { "A", "B", "C", "D" });

            _assert.AreEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:9,代码来源:CompareNewArrayBaseTests.cs

示例2: Test002

        public virtual void Test002()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new NewConstructorData(default(string)));
            var expr2 = xgr.FromFunc(() => new NewConstructorData(default(int)));

            _assert.AreNotEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:9,代码来源:CompareNewBaseTests.cs

示例3: Test007

        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => default(MemberAccessTestData).IntOne);
            var expr2 = xgr.FromFunc(() => default(MemberAccessTestData).StringOne);

            _assert.AreNotEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:9,代码来源:CompareMemberAccessBaseTests.cs

示例4: Test007

        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => default(MethodCallTestData).TwoArgMethod(default(string), default(string)));
            var expr2 = xgr.FromFunc(() => default(MethodCallTestData).TwoArgMethod(default(string), default(string)));

            _assert.AreEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:9,代码来源:CompareMethodCallBaseTests.cs

示例5: Test001

        public void Test001()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.MultiProject(
                ()=>new {
                    FieldOne = 1,
                    FieldTwo = "ABC"
                },
                x=>new InitializerOne {
                    IntField = x.FieldOne,
                    StringField = x.FieldTwo
                },
                _initializerOneTemplate,
                x=>new InitializerTwo {
                    StringFieldOne = x.FieldTwo + "DEF",
                    StringFieldTwo = "GHI" + x.FieldTwo
                },
                _initializerTwoTemplate,
                (x,y)=>new {
                    InitializerOneResult = x,
                    InitializerTwoResult = y
                }
            );

            var inputPlaceholder = xgr.FromFunc(()=>new {
                FieldOne = 1,
                FieldTwo = "ABC"
            });
            var expectations = xgr.FromFunc(inputPlaceholder, x=>new {
                InitializerOneResult = (new InitializerOne {
                        IntField = x.FieldOne,
                        StringField = x.FieldTwo
                    }).StringField + (new InitializerOne
                    {
                        IntField = x.FieldOne,
                        StringField = x.FieldTwo
                    }).IntField,
                InitializerTwoResult = (new InitializerTwo {
                        StringFieldOne = x.FieldTwo + "DEF",
                        StringFieldTwo = "GHI" + x.FieldTwo
                    }).StringFieldTwo + (new InitializerTwo
                    {
                        StringFieldOne = x.FieldTwo + "DEF",
                        StringFieldTwo = "GHI" + x.FieldTwo
                    }).StringFieldOne
            });

            var inputParam = Expression.Parameter(inputPlaceholder.ReturnType);
            var expected = Expression.Lambda(
                ExpressionReplacer.Replace(expectations.Body, inputPlaceholder.Body, inputParam),
                inputParam
            );

            var comparer = new ExpressionComparer();
            Assert.IsTrue(comparer.AreEqual(expected, e1));
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:57,代码来源:ExpressionGenerator.MultiProject.Tests.cs

示例6: Test003

        public virtual void Test003()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => default(MethodCallTestData).IntMethodTwo());
            var expr2 = xgr.FromFunc(() => default(MethodCallTestData).IntMethodOne());

            _assert.AreNotEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:9,代码来源:CompareMethodCallBaseTests.cs

示例7: Test002

        public virtual void Test002()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new string[10]);
            var expr2 = xgr.FromFunc(() => new string[10]);

            _assert.AreEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:9,代码来源:CompareNewArrayBaseTests.cs

示例8: Test003

        public virtual void Test003()
        {
            var xgr = new ExpressionGenerator();

            var p1 = xgr.FromFunc(()=>default(string));
            var expr1 = xgr.FromFunc(p1, a => new NewConstructorData(a));
            var expr2 = xgr.FromFunc(p1, a => new NewConstructorData(a));

            _assert.AreEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:10,代码来源:CompareNewBaseTests.cs

示例9: Test005

        public void Test005()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.FromFunc(() => default(long?));
            var e2 = xgr.FromFunc(() => default(long?));

            var result = xgr.ConvertExpressions(e1, e2);

            Assert.AreEqual(e1.Body, result.Left);
            Assert.AreEqual(e2.Body, result.Right);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:12,代码来源:ExpressionGenerator.Tests.cs

示例10: Test001

        public virtual void Test001()
        {
            var xgr = new ExpressionGenerator();

            // this does not actually generate a ListInit expression
            var expr1 = xgr.FromFunc(()=>new Dictionary<int, int> {
            });
            var expr2 = xgr.FromFunc(() => new Dictionary<int, int> {
            });

            _assert.AreEqual(expr1, expr2);
            Assert.IsNotNull(expr1.Body as MemberInitExpression, "Expected this to be a memberInit");
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:13,代码来源:CompareListInitBaseTests.cs

示例11: Test002

        public virtual void Test002()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new Dictionary<int, int>
            {
                {1, 1 }
            });
            var expr2 = xgr.FromFunc(() => new Dictionary<int, int>
            {
                {1, 1 }
            });

            _assert.AreEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:15,代码来源:CompareListInitBaseTests.cs

示例12: Test002

        public void Test002()
        {
            var xgr = new ExpressionGenerator();
            var l2 = Expression.Lambda<Func<int>>(Expression.Default(typeof(int)));
            var l1 = xgr.FromFunc(l2, i2 => new MemberInitData()
            {
                FieldOne = i2
            });
            var e1 = (MemberInitExpression)l1.Body;
            var e2 = e1.NewExpression;
            var e3 = l2.Body;

            var replace = new Dictionary<Expression, Expression>
            {
                { e2, Expression.New(e2.Constructor) }
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.WasNotProduced(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == replace[e2]);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[0]).Expression == e3);
            assert.WasVisited(e2);
            assert.WasProduced(replace[e2]);
            assert.WasNotProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(e3);

            assert.TotalVisits(3);
            assert.TotalProduced(3);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:32,代码来源:MemberInitVisitorTests.cs

示例13: Test005

        public virtual void Test005()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new {
                IntOne = default(int),
                IntTwo = default(int),
                StringOne = default(string),
                StringTwo = default(string),
            });
            var expr2 = xgr.FromFunc(() => new {
                IntOne = default(int),
                IntTwo = default(int),
                StringOne = default(string),
                StringTwo = default(string),
            });

            _assert.AreEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:19,代码来源:CompareNewBaseTests.cs

示例14: Test007

        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringOne = default(string),
                StringTwo = default(string),
                IntOne = default(int),
                IntTwo = default(int),
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringTwo = default(string),
                IntOne = default(int),
                IntTwo = default(int),
            });

            _assert.AreNotEqual(expr1, expr2);
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:20,代码来源:CompareBindingsBaseTests.cs

示例15: Test001

        public void Test001()
        {
            var xgr = new ExpressionGenerator();
            var xpr = new ExpressionReader();

            var expr = xgr.FromFunc(()=>default(IQueryable<int>).Where(x=>x > 10));
            var expr2 = ((MethodCallExpression)expr.Body).Arguments[1];

            var body = xpr.GetLambda(expr2);

            Assert.AreNotEqual(expr2, body);
            Assert.IsInstanceOfType(body, typeof(LambdaExpression));
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:13,代码来源:ExpressionReader.Tests.cs


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