1.delegate lamba 重写的方法
1 /// <summary> 2 /// Encapsulate shared functionality 3 /// </summary> 4 /// <param name="action">User defined action</param> 5 void UniqueWrapper(Action action) 6 { 7 DoThingsA(); 8 action(); 9 DoThingsB(); 10 } 11 /// <summary> 12 /// New implmentation of A 13 /// </summary> 14 void NewA() 15 { 16 UniqueWrapper(() => 17 { 18 // unique code 19 }); 20 } 21 /// <summary> 22 /// New implementation of B 23 /// </summary> 24 void NewB() 25 { 26 UniqueWrapper(() => 27 { 28 // unique code 29 }); 30 }
2.获取当前类的类名
log.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);