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


C# ExpressionGenerator类代码示例

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


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

示例1: Test002

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

            var e1 = xgr.MultiProject(
                () => new {
                    FieldOne = 1,
                    FieldTwo = "ABC"
                },
                x => x.FieldTwo + x.FieldOne,
                x => "GHI" + x.FieldTwo + x.FieldTwo + "DEF",
                (x, y) => new {
                    InitializerOneResult = x,
                    InitializerTwoResult = y
                }
            );

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

            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,代码行数:35,代码来源:ExpressionGenerator.MultiProject.Tests.cs

示例2: Test003

        public void Test003()
        {
            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>
            {
                {e3,Expression.Constant(1) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

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

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

示例3: 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

示例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: 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

示例6: 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

示例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: Test004

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

            var expr1 = Expression.Parameter(typeof(int));
            var expr2 = Expression.Parameter(typeof(int));

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

示例9: Test003

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

            var expr1 = Expression.Invoke(Expression.Lambda(Expression.Default(typeof(long))));
            var expr2 = Expression.Invoke(Expression.Lambda(Expression.Default(typeof(int))));

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

示例10: 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

示例11: Test001

        public void Test001()
        {
            var xgr = new ExpressionGenerator();
            var expr = Expression.Default(typeof(string));
            var expr2 = xgr.WithType<string>(expr);
            var expr3 = xgr.WithoutType(expr2);

            var xcr = new ExpressionComparer();
            Assert.IsTrue(xcr.AreEqual(expr, expr3));
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:10,代码来源:ExpressionGenerator.Tests.cs

示例12: 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

示例13: Test006

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

            var p1 = Expression.Parameter(typeof(int));
            var p2 = Expression.Parameter(typeof(int));

            var expr1 = Expression.Invoke(Expression.Lambda(Expression.Default(typeof(int)), p1), Expression.Constant(0, typeof(int)));
            var expr2 = Expression.Invoke(Expression.Lambda(Expression.Default(typeof(int)), p2), Expression.Default(typeof(int)));

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

示例14: 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

示例15: Test004

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

            var expr = xgr.FromFunc(() => default(IQueryable<int>).Where(x => x > 10));

            var result = xpr.GetLambda(expr);

            Assert.AreEqual(expr, result);
            Assert.IsInstanceOfType(result, typeof(LambdaExpression));
        }
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:12,代码来源:ExpressionReader.Tests.cs


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