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


C# ExpressionGenerator.MultiProject方法代码示例

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


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

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

示例2: Test004

        public void Test004()
        {
            var xgr = new ExpressionGenerator();
            var q = Enumerable.Range(0, 1).Select(x => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            }).AsQueryable();

            var e1 = xgr.MultiProject(
                q,
                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 inner1 = e1.Expression as MethodCallExpression;
            var inner2 = inner1.Arguments[1] as UnaryExpression;
            var inner3 = inner2.Operand as LambdaExpression;

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


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