本文整理汇总了C#中TypeMapper.Map方法的典型用法代码示例。如果您正苦于以下问题:C# TypeMapper.Map方法的具体用法?C# TypeMapper.Map怎么用?C# TypeMapper.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeMapper
的用法示例。
在下文中一共展示了TypeMapper.Map方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanMapSimpleNullableTypes
public void CanMapSimpleNullableTypes(Type type, string expectedParamType, string expectedFormat = "")
{
var mapper = new TypeMapper();
var inputParam = new InputParameter { Type = type };
var param = mapper.Map(inputParam);
Assert.AreEqual(expectedParamType, param.type);
Assert.AreEqual(expectedFormat, param.format);
Assert.IsEmpty(mapper.Models);
}
示例2: Bug002__MapToInterfaceProperty_WhereTargetInterfaceIsDifferentThanSourceType
public void Bug002__MapToInterfaceProperty_WhereTargetInterfaceIsDifferentThanSourceType()
{
var c1 = new Bug002_Class_One();
c1.Id = 1;
c1.Property = new Bug002_Class_One();
c1.Property.Id = 2;
var tm = new TypeMapper();
var clone = tm.Map<Bug002_Class_Two>(c1);
Assert.IsNotNull(clone);
Assert.AreEqual(clone.Id, c1.Id);
Assert.AreEqual(clone.Property.Id, c1.Property.Id);
Assert.IsNull(clone.Property.Property);
}
示例3: SetUp
public void SetUp()
{
_mapper = new TypeMapper();
_mapper.Map<IList, ArrayList>();
//_mapper.Map(typeof(IList), typeof(ArrayList));
_mapper.Map(typeof(IList<>), typeof(List<>));
_mapper.Map(typeof(IPropertyHelper<>), typeof(PropertyHelper<>));
}
示例4: Bug003_MappingFailsWhenSourceHasReadOnlyPropertyWithNullValue
public void Bug003_MappingFailsWhenSourceHasReadOnlyPropertyWithNullValue()
{
var c1 = new Bug003_Class_One();
var tm = new TypeMapper();
var clone = tm.Map<Bug003_Class_One>(c1);
Assert.IsNotNull(clone);
Assert.AreEqual(clone.Id, c1.Id);
}
示例5: Bug006_ReuseTargetCollectionsWhenPossible_false__Fails_to_create_new_collection
public void Bug006_ReuseTargetCollectionsWhenPossible_false__Fails_to_create_new_collection()
{
var c1 = new Bug006_Class_One { Name = "1" };
var trp1 = new Bug006_Class_One
{
Name = "trp1"
};
var trp2 = new Bug006_Class_One
{
Name = "trp2"
};
c1.Items.Add(trp1);
c1.Items.Add(trp2);
var c2 = new Bug006_Class_One();
var mo = new MappingOptions()
{
ReuseTargetCollectionsWhenPossible = false,
};
var tm = new TypeMapper();
tm.Map(c1, c2, mo);
Assert.AreEqual(c1.Name, c2.Name);
// when the bug wasn't fixed, c2.Items.Count would be 0
Assert.AreEqual(c1.Items.Count, c2.Items.Count);
for (int i = 0; i < c1.Items.Count; i++)
{
Assert.AreEqual(c1.Items[i].Name, c2.Items[i].Name);
}
}
示例6: Bug005_mapping_fails_when_type_contains_list_property_without_a_setter
public void Bug005_mapping_fails_when_type_contains_list_property_without_a_setter()
{
var c1 = new Bug005_Class_One { Name = "1" };
var c1_1 = new Bug005_Class_One { Name = "1_1" };
var c1_2 = new Bug005_Class_One { Name = "1_2" };
var c1_3 = new Bug005_Class_One { Name = "1_3" };
c1.Items.Add(c1_1);
c1.Items.Add(c1_2);
c1.Items.Add(c1_3);
var c2 = new Bug005_Class_One();
var tm = new TypeMapper();
tm.Map(c1, c2);
Assert.AreEqual(c1.Name, c2.Name);
Assert.AreEqual(c1.Items.Count, c2.Items.Count);
for(int i = 0; i < c1.Items.Count; i++)
{
Assert.AreEqual(c1.Items[i].Name, c2.Items[i].Name);
}
}
示例7: Bug004_CloneFailsOnTypeWithReadOnlyPropertiesWhichThrowException
public void Bug004_CloneFailsOnTypeWithReadOnlyPropertiesWhichThrowException()
{
var c1 = new Bug004_Class_One();
var tm = new TypeMapper();
var clone = tm.Map<Bug004_Class_One>(c1);
Assert.IsNotNull(clone);
Assert.AreEqual(clone.Id, c1.Id);
}