本文整理汇总了C#中TypeMapper.DeepClone方法的典型用法代码示例。如果您正苦于以下问题:C# TypeMapper.DeepClone方法的具体用法?C# TypeMapper.DeepClone怎么用?C# TypeMapper.DeepClone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeMapper
的用法示例。
在下文中一共展示了TypeMapper.DeepClone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandlesCircularReferences__ObjectReferencesSelfDirectly
public void HandlesCircularReferences__ObjectReferencesSelfDirectly()
{
var n = new LinkedListNode { Id = 13 };
n.Next = n;
n.Previous = n;
var tm = new TypeMapper();
var clone = tm.DeepClone<LinkedListNode>(n);
Assert.AreEqual(13, clone.Id);
Assert.AreSame(n, n.Next);
Assert.AreSame(n, n.Previous);
}
示例2: CanCloneAnObject
public void CanCloneAnObject()
{
var st = new SimpleType();
st.EnumProperty = DayOfWeek.Friday;
st.IntegerProperty = 13;
st.StringProperty = "some string";
var tm = new TypeMapper();
var clone = tm.DeepClone<SimpleType>(st);
Assert.AreEqual(st.EnumProperty, clone.EnumProperty);
Assert.AreEqual(st.IntegerProperty, clone.IntegerProperty);
Assert.AreEqual(st.StringProperty, clone.StringProperty);
}
示例3: Bug001__MapToInterfaceProperty
public void Bug001__MapToInterfaceProperty()
{
var c1 = new Bug001_Class();
c1.Id = 1;
c1.Property = new Bug001_Class();
c1.Property.Id = 2;
var tm = new TypeMapper();
var clone = tm.DeepClone(c1);
Assert.IsNotNull(clone);
Assert.AreEqual(clone.Id, c1.Id);
Assert.AreEqual(clone.Property.Id, c1.Property.Id);
Assert.IsNull(clone.Property.Property);
}
示例4: CanCloneToSubType
public void CanCloneToSubType()
{
var st = new SimpleType2();
st.EnumProperty = DayOfWeek.Friday;
st.IntegerProperty = 13;
st.StringProperty = "some string";
st.AnotherProperty = 1;
var tm = new TypeMapper();
// clone SimpleType2 to its subtype SimpleType
var clone = tm.DeepClone<SimpleType>(st);
Assert.AreEqual(st.EnumProperty, clone.EnumProperty);
Assert.AreEqual(st.IntegerProperty, clone.IntegerProperty);
Assert.AreEqual(st.StringProperty, clone.StringProperty);
Assert.IsFalse(clone is SimpleType2);
Assert.IsTrue(clone is SimpleType);
}
示例5: Bug005__CloneDataTable__NotSupported_Thrown
public void Bug005__CloneDataTable__NotSupported_Thrown()
{
var dt = new DataTable();
dt.Columns.Add("str", typeof(string));
dt.Columns.Add("int", typeof(int));
dt.Rows.Add("one", 1);
dt.Rows.Add("two", 2);
var tm = new TypeMapper();
var clone = tm.DeepClone(dt);
Assert.IsNotNull(clone);
Assert.AreEqual(dt.Rows.Count, clone.Rows.Count);
Assert.AreEqual(dt.Columns.Count, clone.Columns.Count);
}
示例6: HandlesCircularReferences__ObjectReferencesSelfIndirectly
public void HandlesCircularReferences__ObjectReferencesSelfIndirectly()
{
var n0 = new LinkedListNode { Id = 0 };
var n1 = new LinkedListNode { Id = 1 };
var n2 = new LinkedListNode { Id = 2 };
var n3 = new LinkedListNode { Id = 3 };
n0.Next = n1;
n1.Next = n2;
n2.Next = n3;
n3.Next = n0;
n0.Previous = n3;
n1.Previous = n0;
n2.Previous = n1;
n3.Previous = n2;
var tm = new TypeMapper();
var clone = tm.DeepClone<LinkedListNode>(n3);
Assert.AreEqual(3, clone.Id);
Assert.AreEqual(2, clone.Previous.Id);
Assert.AreEqual(1, clone.Previous.Previous.Id);
Assert.AreEqual(0, clone.Previous.Previous.Previous.Id);
Assert.AreEqual(3, clone.Previous.Previous.Previous.Previous.Id);
Assert.AreEqual(0, clone.Next.Id);
Assert.AreEqual(1, clone.Next.Next.Id);
Assert.AreEqual(2, clone.Next.Next.Next.Id);
Assert.AreEqual(3, clone.Next.Next.Next.Next.Id);
Assert.AreSame(clone, clone.Next.Next.Next.Next);
Assert.AreSame(clone, clone.Previous.Previous.Previous.Previous);
}