本文整理汇总了C#中MemberMapper.AddCustomConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# MemberMapper.AddCustomConstructor方法的具体用法?C# MemberMapper.AddCustomConstructor怎么用?C# MemberMapper.AddCustomConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberMapper
的用法示例。
在下文中一共展示了MemberMapper.AddCustomConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomConstructorOnMapperIsRespected
public void CustomConstructorOnMapperIsRespected()
{
var mapper = new MemberMapper();
mapper.AddCustomConstructor<NestedDestinationType>(() => new NestedDestinationType(1));
var source = new SourceType
{
Foo = new NestedSourceType
{
ID = 10
}
};
var result = mapper.Map<SourceType, DestinationType>(source);
Assert.AreEqual(1, result.Foo.OtherID);
Assert.AreEqual(10, result.Foo.ID);
}
示例2: CustomConstructorOnProposalTakesPrecedence
public void CustomConstructorOnProposalTakesPrecedence()
{
var mapper = new MemberMapper();
mapper.AddCustomConstructor<NestedDestinationType>(() => new NestedDestinationType(1));
mapper.CreateMapProposal<SourceType, DestinationType>()
.WithConstructorFor<NestedDestinationType>((src, dest) => new NestedDestinationType(2))
.FinalizeMap();
var source = new SourceType
{
Foo = new NestedSourceType
{
ID = 10
}
};
var result = mapper.Map<SourceType, DestinationType>(source);
Assert.AreEqual(2, result.Foo.OtherID);
Assert.AreEqual(10, result.Foo.ID);
}
示例3: MemberIsAddedToIncompatibleMappingsIfConversionCantBeMade
public void MemberIsAddedToIncompatibleMappingsIfConversionCantBeMade()
{
var mapper = new MemberMapper();
mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true;
mapper.AddCustomConstructor<Guid>(() => Guid.NewGuid());
var result = mapper.Map<DateTimeSource, GuidDestination>(new DateTimeSource());
}