/// <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;
posted on 2012-07-27 17:03  凌度  阅读(1389)  评论(0编辑  收藏  举报