Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- var x = 1;
- var y = "asdf";
- new { x, y }.Log();
- }
- private static void Log<T>(this T obj, [CallerMemberName] string methodName = null)
- {
- Console.WriteLine(methodName);
- foreach (var prop in typeof(T).GetProperties())
- {
- Console.WriteLine("{0}={1}", prop.Name, prop.GetValue(obj));
- }
- }
- private static void LogExpression(Expression<Func<object>> l)
- {
- Console.WriteLine("{0}={1}", l.Body.ToString(), l.Compile()());
- }
Advertisement
Add Comment
Please, Sign In to add comment