public class ReportTypeElement
{
private List<ReportTypeInfo> ReportTypeInfoList { get; set; }
/// <summary>
/// 0: Delete; 1: normal; 2: new; 3: modify
/// </summary>
private int Status { get; set; }
}
public class ReportTypeInfo
{
public String Name { get; set; }
public DateTimeList dateTimeList { get; set; }
/// <summary>
/// 0: Delete; 1: normal; 2: new; 3: modify
/// </summary>
private int Status { get; set; }
}
是一层层嵌套的 请问 如何进行深拷贝 我都困扰了 两天了 谢谢
6 个解决方案
#1
有两天时间,拷贝到18层地狱的代码都写完了。
#2
搞定了 呵呵 小问题 谢谢
#3
/// <summary>
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}
#4
这个怎么用啊 我指的是Dictionary 和 内嵌的list 层层的new 形成 深拷贝
#5
C# code/// <summary>
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}
object obj = Clone(ReportTypeIndexDocList );
将obj 转化成Dictionary<String, ReportTypeElement> 类型即可
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}
object obj = Clone(ReportTypeIndexDocList );
将obj 转化成Dictionary<String, ReportTypeElement> 类型即可
--reply by
CSDN Study V1.0.0.3 (starts_2000)
#6
很管用 谢谢 两位大牛
#1
有两天时间,拷贝到18层地狱的代码都写完了。
#2
搞定了 呵呵 小问题 谢谢
#3
/// <summary>
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}
#4
这个怎么用啊 我指的是Dictionary 和 内嵌的list 层层的new 形成 深拷贝
#5
C# code/// <summary>
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}
object obj = Clone(ReportTypeIndexDocList );
将obj 转化成Dictionary<String, ReportTypeElement> 类型即可
/// 得到一个对象的克隆
/// </summary>
public static object Clone(object obj)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, obj);
memoryStream.Position = 0;
return formatter.Deserialize(memoryStream);
}
object obj = Clone(ReportTypeIndexDocList );
将obj 转化成Dictionary<String, ReportTypeElement> 类型即可
--reply by
CSDN Study V1.0.0.3 (starts_2000)
#6
很管用 谢谢 两位大牛