/// <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;