staafl

logging utils

Jan 17th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. var x = 1;
  4. var y = "asdf";
  5. new { x, y }.Log();
  6. }
  7.  
  8. private static void Log<T>(this T obj, [CallerMemberName] string methodName = null)
  9. {
  10. Console.WriteLine(methodName);
  11. foreach (var prop in typeof(T).GetProperties())
  12. {
  13. Console.WriteLine("{0}={1}", prop.Name, prop.GetValue(obj));
  14. }
  15. }
  16.  
  17. private static void LogExpression(Expression<Func<object>> l)
  18. {
  19. Console.WriteLine("{0}={1}", l.Body.ToString(), l.Compile()());
  20. }
Advertisement
Add Comment
Please, Sign In to add comment