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


C# MemberMapper.CreateMap方法代码示例

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


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

示例1: BaseClassMappingAndInheritedClassMappingIsRespected

        public void BaseClassMappingAndInheritedClassMappingIsRespected()
        {
            var mapper = new MemberMapper();

              mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true;

              mapper.CreateMap<SourceBase, DestinationBase>(customMapping: src => new DestinationBase
              {
            Test = src.ID
              });

              mapper.CreateMap<SecondSourceInherited, SecondDestinationInherited>(customMapping: src => new SecondDestinationInherited
              {
            Bar = src.Foo
              });

              var result = mapper.Map<SecondSourceInherited, SecondDestinationInherited>(new SecondSourceInherited
              {
            ID = 10,
            Foo = "test"
              });

              Assert.AreEqual(10, result.Test);
              Assert.AreEqual("test", result.Bar);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:25,代码来源:InheritanceTests.cs

示例2: CustomMappingIsRespected

        public void CustomMappingIsRespected()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<Customer, SimpleCustomerDto>(customMapping: c => new
              {
            FullName = c.FirstName + " " + c.LastName.ToString(),
            AddressLine = c.Address.Street + " " + c.Address.HouseNumber,
            EmailAddress = c.EmailAddress.Address
              });

              var customer = new Customer
              {
            FirstName = "Test",
            LastName = "Test",
            EmailAddress = new EmailAddress
            {
              Address = "[email protected]"
            },
            CustomerID = 1,
            Address = new Address
            {
              Street = "test",
              HouseNumber = "10",
              ZipCode = "1111AB",
              City = "test"
            }
              };

              var dto = mapper.Map<Customer, SimpleCustomerDto>(customer);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:31,代码来源:CustomMappingTests.cs

示例3: ComplexTypeMappingRespectsExistingMapping

        public void ComplexTypeMappingRespectsExistingMapping()
        {
            var mapper = new MemberMapper();

              var proposed = mapper.CreateMap(typeof(ComplexSourceType), typeof(ComplexDestinationType),
              (s, p, option) =>
              {
            if (s.Name == "Name")
            {
              option.IgnoreMember();
            }
              });

              proposed.FinalizeMap();

              var source = new ComplexSourceType
              {
            ID = 5,
            Complex = new NestedSourceType
            {
              ID = 10,
              Name = "test"
            }
              };

              var destination = mapper.Map<ComplexSourceType, ComplexDestinationType>(source);

              Assert.AreEqual(destination.ID, 5);
              Assert.IsNotNull(destination.Complex);
              Assert.AreNotEqual(destination.Complex.Name, source.Complex.Name);
        }
开发者ID:JulianR,项目名称:MemberMapper,代码行数:31,代码来源:MemberMapperTests.cs

示例4: ClearMapCacheIsRespected

        public void ClearMapCacheIsRespected()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType>(customMapping: src => new
              {
            ID = src.ID * 10,
            Name = src.Name + src.Name
              });

              var source = new SourceType
              {
            ID = 10,
            Name = "x"
              };

              var result = mapper.Map<DestinationType>(source);

              Assert.AreEqual(100, result.ID);
              Assert.AreEqual("xx", result.Name);

              mapper.ClearMapCache();

              result = mapper.Map<DestinationType>(source);

              Assert.AreEqual(10, result.ID);
              Assert.AreEqual("x", result.Name);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:28,代码来源:MemberMapperTests.cs

示例5: NestedPropertyWithCustomMappingWorks

        public void NestedPropertyWithCustomMappingWorks()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<Address, AddressDto>(src => new AddressDto
              {
            CountryName = src.Country.Name
              });

              var projection = mapper.Project<CustomerSingleAddress, CustomerSingleAddressDto>();

              var method = projection.Compile();

              var result = method(new CustomerSingleAddress
              {
            Address =
              new Address
              {
            Country = new Country
            {
              Name = "X"
            }
              }
              });

              Assert.AreEqual("X", result.Address.CountryName);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:27,代码来源:ProjectionCustomMappingsTests.cs

示例6: InvokingMapWithoutParameterAsMapWithParameterThrows

        public void InvokingMapWithoutParameterAsMapWithParameterThrows()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType>();

              var result = mapper.Map(new SourceType(), new DestinationType(), 1);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:8,代码来源:ParameterTests.cs

示例7: MapForMapWithParameterThrowsForMapWithoutParameter

        public void MapForMapWithParameterThrowsForMapWithoutParameter()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType>();

              mapper.Map<SourceType, DestinationType, int>(new SourceType(), 0);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:8,代码来源:GenericsTests.cs

示例8: GetMapWorks

        public void GetMapWorks()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType>();

              Assert.IsNotNull(mapper.GetMap<SourceType, DestinationType>());
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:8,代码来源:GenericsTests.cs

示例9: HasMapWorks

        public void HasMapWorks()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType>();

              Assert.IsTrue(mapper.HasMap<SourceType, DestinationType>());
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:8,代码来源:GenericsTests.cs

示例10: TypeMappingsAreNotCachedWhenRecursionDepthIsLimited

        public void TypeMappingsAreNotCachedWhenRecursionDepthIsLimited()
        {
            var mapper = new MemberMapper();

              mapper.Options.Cloning.MaxCloneDepth = 2;

              mapper.CreateMap<ClassA, ClassA>();

              mapper.CreateMap<ClassB, ClassB>();

              var result = mapper.Map<ClassB, ClassB>(new ClassB
              {
            FooC = new ClassC
            {
              FooA = new ClassA
              {

              }
            }
              });

              Assert.IsNotNull(result);
              Assert.IsNotNull(result.FooC);
              Assert.IsNotNull(result.FooC.FooA);

              var resultOther = mapper.Map<ClassA, ClassA>(new ClassA
              {
            FooB = new ClassB
            {
              FooC = new ClassC
              {
            FooA = new ClassA
            {

            }
              }
            }
              });

              Assert.IsNotNull(resultOther);
              Assert.IsNotNull(resultOther.FooB);
              Assert.IsNotNull(resultOther.FooB.FooC);
              Assert.IsNull(resultOther.FooB.FooC.FooA);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:44,代码来源:RecursiveMapTests.cs

示例11: ConversionFunctionIsValidatedOnArgumentCount

        public void ConversionFunctionIsValidatedOnArgumentCount()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<Source, Destination>(options: (ctx, options) =>
              {
            Expression<Func<string, string, string, int>> func = ((s, y, z) => s.Length);
            options.Convert(func);
              });
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:10,代码来源:ConversionFunctionTests.cs

示例12: MappingFunctionIsSetCorrectly

        public void MappingFunctionIsSetCorrectly()
        {
            var mapper = new MemberMapper();

              var map = mapper.CreateMap(typeof(Source), typeof(Destination));

              Assert.IsNotNull(map.MappingFunction);
              Assert.IsNotNull(map as MemberMap<Source, Destination>);
              Assert.IsNotNull(((MemberMap<Source, Destination>)map).MappingFunction);
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:10,代码来源:MemberMapMappingFunctionTests.cs

示例13: Delete

        //
        // GET: /Group/Delete/5
        public ActionResult Delete(int id)
        {
            var memberMapper = new MemberMapper();
              memberMapper.CreateMap<Group, GroupModel>();

              var ctx = new CourseContext();

              var result = memberMapper.Map<Group, GroupModel>(ctx.Groups.FirstOrDefault(c => c.ID == id));

              return View(result);
        }
开发者ID:sTodorov,项目名称:Course-manager,代码行数:13,代码来源:GroupController.cs

示例14: Edit

        public ActionResult Edit(int id)
        {
            var memberMapper = new MemberMapper();
              memberMapper.CreateMap<Semester, SemesterModel>();

              var ctx = new CourseContext();

              var result = memberMapper.Map<Semester, SemesterModel>(ctx.Semesters.FirstOrDefault(c => c.ID == id));

              return View(result);
        }
开发者ID:sTodorov,项目名称:Course-manager,代码行数:11,代码来源:SemesterController.cs

示例15: GetMapThrowsForMapWithParameter

        public void GetMapThrowsForMapWithParameter()
        {
            var mapper = new MemberMapper();

              mapper.CreateMap<SourceType, DestinationType, int>((s, i) => new DestinationType
              {

              });

              mapper.GetMap<SourceType, DestinationType>();
        }
开发者ID:JulianR,项目名称:ThisMember,代码行数:11,代码来源:GenericsTests.cs


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