轻设计 / 轻生活 / 轻日记 / 轻梦想
=== zhoumojianshe ===
/// <summary> /// 实现对象的深拷贝 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <param name="obj">对象</param> /// <returns>T</returns> public static T CreateDeepCopy<T>(T obj) { T t; MemoryStream memoryStream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(memoryStream, obj); memoryStream.Position = 0; t = (T)formatter.Deserialize(memoryStream); return t; }
调用方法:
CategoryInfo category = CreateDeepCopy<CategoryInfo>((CategoryInfo)bsCategory.Current);