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

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2022-02-14
  • 2022-02-07
  • 2021-07-18
  • 2022-12-23
  • 2021-10-07
猜你喜欢
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案