2013年7月21日

非序列化字段与反序列化完成后回调

摘要: 示例:public class Class1 : IDeserializationCallback{ public DateTime Birthday { get; set; } [NonSerialized] public int Age; public void OnDeserialization(object sender) { Age = DateTime.Now.Year - Birthday.Year; }} 阅读全文

posted @ 2013-07-21 14:34 yao2yao4 阅读(191) 评论(0) 推荐(0) 编辑

不同类型的委托变量的共同类型

摘要: 代码示例:var A = new Dictionary();A.Add(0, new Func(() => 123));A.Add(1, new Func(i => i * i));var a = A[0].Method.Invoke(this, null);var b = A[1].Method.Invoke(this, new object[] { 3 }); 阅读全文

posted @ 2013-07-21 11:18 yao2yao4 阅读(180) 评论(0) 推荐(0) 编辑

实现IDisposable接口的模式

摘要: 代码:public class Class2 : IDisposable{ ~Class2() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { //todo:清理托管资源 } ... 阅读全文

posted @ 2013-07-21 09:03 yao2yao4 阅读(169) 评论(0) 推荐(0) 编辑

导航