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


C# Mapper.BuildClassMap方法代码示例

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


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

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

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

示例3: When_Enumerating_Bindings_Then_MemberDefinitiontType_Is_Auto

        public void When_Enumerating_Bindings_Then_MemberDefinitiontType_Is_Auto()
        {
            // Arrange
            var sut = new Mapper();
            var map = sut.BuildClassMap<SimpleFrom, SimpleTo>().Map;

            // Act
            var res = map.Bindings;

            // Assert
            Assert.IsTrue(res.All(b => b.BindingType == BindingType.Auto));
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:12,代码来源:Given_Auto_Generated_Map.cs

示例4: When_Mapping_Then_Unflattens

        public void When_Mapping_Then_Unflattens()
        {
            var dto = new Dto
            {
                P1 = "A",
                P2 = "B",
                P3 = "C"
            };

            // Arrange
            var mapper = new Mapper();
            mapper.BuildClassMap<Dto, SubDomainModel>();
            mapper.BuildClassMap<Dto, DomainModel>().For(t => t.SubModel, o => o.From(x => x));

            // Act
            var model = mapper.Map<Dto, DomainModel>(dto);

            // Assert
            Assert.AreEqual("A", model.SubModel.P1);
            Assert.AreEqual("B", model.SubModel.P2);
            Assert.AreEqual("C", model.P3);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:22,代码来源:Given_ClassMap_Unflattening.cs

示例5: When_Mapping_Then_Can_Project_Inline

        public void When_Mapping_Then_Can_Project_Inline()
        {
            var dto = new Dto
            {
                P1 = "A",
                P2 = "B",
                P3 = "C"
            };

            // Arrange
            var mapper = new Mapper();
            mapper.BuildClassMap<Dto, SubDomainModel>();
            mapper.BuildClassMap<Dto, DomainModel>().For(t => t.P3, o => o.From(x => x.P2, y => y + "Hello"));

            // Act
            var model = mapper.Map<Dto, DomainModel>(dto);

            // Assert
              //  Assert.AreEqual("A", model.SubModel.P1);
              //  Assert.AreEqual("B", model.SubModel.P2);
            Assert.AreEqual("BHello", model.P3);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:22,代码来源:Given_ClassMap_Unflattening.cs

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

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

示例8: When_Mapping_Derived_Instance_As_Base_Then_Maps_Polymorphically_As_Derived

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

            sut.BuildPolymorphicMap<VehicleFrom, VehicleTo>()
               .AddPolymorph<CarFrom, CarTo>();

            sut.BuildClassMap<CarFrom, CarTo>();

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

            // Act
            var to = sut.Map<VehicleFrom, VehicleTo>(from);
            var res = to as CarTo;

            // Assert
            Assert.NotNull(res);
            Assert.AreEqual("Porsche", res.Name);
            Assert.AreEqual(from.NumSeats, res.NumSeats);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:21,代码来源:Given_PolymorphicMap.cs

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

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

示例11: When_Mapping_Object_With_Complex_Enumerable_Then_Maps

        public void When_Mapping_Object_With_Complex_Enumerable_Then_Maps()
        {
            // Arrange
            var sut = new Mapper();
            sut.BuildClassMap<SimpleFrom, SimpleTo>();
            sut.BuildClassMap<ContainsEnumerableTFrom, ContainsListTTo>();
            var from = new ContainsEnumerableTFrom
            {
                Collection = new List<SimpleFrom>
                {
                    new SimpleFrom {StringProp = "One", IntField = 1},
                    new SimpleFrom {StringProp = "Two", IntField = 2},
                    new SimpleFrom {StringProp = "Three", IntField = 3},
                }
            };

            // Act
            var res = sut.Map<ContainsListTTo>(from);

            // Assert
            KKAssert.AreEqualByValue(from, res);
        }
开发者ID:jonclare,项目名称:KodeKandy,代码行数:22,代码来源:Given_Mapper.cs


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