}
[c#] 利用序列化进行对象深度clone
转载/// <summary>
/// 利用序列化进行对象拷贝,要求对象是序列化的
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="item">源对象</param>
/// <returns>克隆对象</returns>
public static T Clone<T>(T item)
where T : class
{
T result = default(T);
if (null != item)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, item);
ms.Seek(0, SeekOrigin.Begin);
}
return result;
result = bf.Deserialize(ms) as T;
下一篇:[Linux] 关机和重启命令

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
c# 泛型对象序列化或者泛型对象列表序列化
c# 泛型对象序列化或者泛型对象列表序列化
职场 c# 休闲 泛型对象序列化 泛型对象列表序列化 -
C# 实现复杂对象的序列化与反序列化
C# 实现复杂对象的序列
c# html hive