本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例6: InvokingMapWithoutParameterAsMapWithParameterThrows
public void InvokingMapWithoutParameterAsMapWithParameterThrows()
{
var mapper = new MemberMapper();
mapper.CreateMap<SourceType, DestinationType>();
var result = mapper.Map(new SourceType(), new DestinationType(), 1);
}
示例7: MapForMapWithParameterThrowsForMapWithoutParameter
public void MapForMapWithParameterThrowsForMapWithoutParameter()
{
var mapper = new MemberMapper();
mapper.CreateMap<SourceType, DestinationType>();
mapper.Map<SourceType, DestinationType, int>(new SourceType(), 0);
}
示例8: GetMapWorks
public void GetMapWorks()
{
var mapper = new MemberMapper();
mapper.CreateMap<SourceType, DestinationType>();
Assert.IsNotNull(mapper.GetMap<SourceType, DestinationType>());
}
示例9: HasMapWorks
public void HasMapWorks()
{
var mapper = new MemberMapper();
mapper.CreateMap<SourceType, DestinationType>();
Assert.IsTrue(mapper.HasMap<SourceType, DestinationType>());
}
示例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);
}
示例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);
});
}
示例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);
}
示例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);
}
示例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);
}
示例15: GetMapThrowsForMapWithParameter
public void GetMapThrowsForMapWithParameter()
{
var mapper = new MemberMapper();
mapper.CreateMap<SourceType, DestinationType, int>((s, i) => new DestinationType
{
});
mapper.GetMap<SourceType, DestinationType>();
}