本文整理汇总了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);
}
示例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!
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}