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


C# Mapper.Merge方法代码示例

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


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

示例1: When_Mapping_Flattening_Class_Then_Maps

        public void When_Mapping_Flattening_Class_Then_Maps()
        {
            // Arrange
            var sut = new Mapper();
            sut.BuildClassMap<FlatteningFrom, FlatteningTo>();
            var from = new FlatteningFrom {Child = new FlatteningFrom.FlatteningChildFrom {Name = "Bob"}};
            var to = new FlatteningTo();

            // Act
            sut.Merge(from, to);

            // Assert
            Assert.AreEqual(from.Child.Name, to.ChildName);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:14,代码来源:Given_Auto_Generated_Map.cs

示例2: When_Mapping_Nested_Class_Then_Maps

        public void When_Mapping_Nested_Class_Then_Maps()
        {
            // Arrange
            var sut = new Mapper();
            sut.BuildClassMap<NestedFrom, NestedTo>();
            sut.BuildClassMap<NestedFrom.NestedChildFrom, NestedTo.NestedChildTo>();
            var from = new NestedFrom {Child = new NestedFrom.NestedChildFrom {Name = "Bob"}};
            var to = new NestedTo {Child = new NestedTo.NestedChildTo()};

            // Act
            sut.Merge(from, to);

            // Assert
            Assert.AreEqual(from.Child.Name, to.Child.Name);
            Assert.AreNotEqual(from.Child, to.Child); // Ensure mapping of class not ref copying!
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:16,代码来源:Given_Auto_Generated_Map.cs

示例3: When_Mapping_Derived_Instance_Then_Uses_Inherited_Binding

        public void When_Mapping_Derived_Instance_Then_Uses_Inherited_Binding()
        {
            // Arrange
            var sut = new Mapper();

            sut.BuildClassMap<VehicleFrom, VehicleTo>()
               .For(x => x.Name, o => o.Custom(_ => "Ferrari"));
            sut.BuildClassMap<CarFrom, CarTo>()
               .InheritsFrom<VehicleFrom, VehicleTo>();

            var from = new CarFrom() {Name = "Porsche", NumSeats = 4};
            var to = new CarTo();

            // Act
            sut.Merge(from, to);

            // Assert
            Assert.AreEqual("Ferrari", to.Name);
            Assert.AreEqual(from.NumSeats, to.NumSeats);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:20,代码来源:Given_Mapping_With_Inheritance.cs

示例4: When_Mapping_With_Conversion_Then_Maps

        public void When_Mapping_With_Conversion_Then_Maps()
        {
            // Arrange
            var sut = new Mapper();
            sut.BuildClassMap<ConversionFrom, ConversionTo>();
            sut.BuildConversion<string, int>().Explictly(x => x.Count());
            var from = new ConversionFrom {Age = "Twelve"};
            var to = new ConversionTo {Age = 6};

            // Act
            sut.Merge(from, to);

            // Assert
            Assert.AreEqual(from.Age.Count(), to.Age);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:15,代码来源:Given_Auto_Generated_Map.cs

示例5: When_Mapping_Simple_Class_Then_Maps

        public void When_Mapping_Simple_Class_Then_Maps()
        {
            // Arrange
            var sut = new Mapper();
            sut.BuildClassMap<SimpleFrom, SimpleTo>();
            var from = new SimpleFrom() {StringProp = "Bob", IntField = 20};
            var to = new SimpleTo();

            // Act
            sut.Merge(from, to);

            // Assert
            Assert.AreEqual(from.StringProp, to.StringProp);
            Assert.AreEqual(from.IntField, to.IntField);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:15,代码来源:Given_Auto_Generated_Map.cs

示例6: When_Mapping_Value_Type_To_Class_Then_Maps

        public void When_Mapping_Value_Type_To_Class_Then_Maps()
        {
            // Arrange
            var sut = new Mapper();
            sut.BuildClassMap<int, SimpleTo>()
               .For(x => x.IntField, o => o.Custom(ctx => (int) ctx.FromInstance))
               .For(x => x.StringProp, o => o.Custom(ctx => ((int) ctx.FromInstance).ToString()));
            const int from = 12;
            var to = new SimpleTo();

            // Act
            sut.Merge(from, to);

            // Assert
            Assert.AreEqual(from, to.IntField);
            Assert.AreEqual("12", to.StringProp);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:17,代码来源:Given_Auto_Generated_Map.cs


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