2011年3月16日
摘要: 通过序列化来实现对象深度复制。1 public static T Clone<T>(T obj)2 {3 object result;4 using (var memoryStream = new MemoryStream())5 {6 var binaryFormatter = new BinaryFormatter();7 binaryFormatter.Serialize(memoryStream, obj);8 memoryStream.Seek(0, SeekOrigin.Begin);9 result = binaryFormatter.Deserialize(memo 阅读全文
posted @ 2011-03-16 15:02 rroo 阅读(218) 评论(0) 推荐(0) 编辑
摘要: using System; public class SingletonTemplate<T> { private static object _locker = new object(); private static SingletonTemplate<T> _obj = null; private static T _instance; private SingletonTemplate() { _instance = Activator.CreateInstance<T>(); } public static T Instance { get { i 阅读全文
posted @ 2011-03-16 14:56 rroo 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 将创建树形数据结构抽象出功能类1 using System.Collections.Generic;2 using System;3 4 public class TreeTemplate<T>5 {6 private readonly List<T> _data = new List<T>();7 8 public TreeTemplate(List<T> items)9 {10 _data = items;11 }12 public List<Node<T>> GetTree(Func<T, bool> i 阅读全文
posted @ 2011-03-16 14:26 rroo 阅读(703) 评论(0) 推荐(0) 编辑