using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Runtime.Serialization;
|
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Text;
|
|
namespace ZY.Mes.Until
|
{
|
public class DeepCopy
|
{
|
/// <summary>
|
/// 深拷贝
|
/// </summary>
|
/// <typeparam name="T"></typeparam>
|
/// <param name="List">The list.</param>
|
/// <returns>List{``0}.</returns>
|
public static T Clone<T>(T List) where T : class
|
{
|
using (Stream objectStream = new MemoryStream())
|
{
|
IFormatter formatter = new BinaryFormatter();
|
formatter.Serialize(objectStream, List);
|
objectStream.Seek(0, SeekOrigin.Begin);
|
return formatter.Deserialize(objectStream) as T;
|
}
|
}
|
}
|
}
|