Created
October 9, 2014 08:29
-
-
Save svick/97c6a8c8b006283c96e2 to your computer and use it in GitHub Desktop.
How to use caller info attributes on .Net 4.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
namespace System.Runtime.CompilerServices | |
{ | |
class CallerMemberNameAttribute : Attribute | |
{ } | |
} | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
LogMessage("message"); | |
} | |
public static void LogMessage(string message, [CallerMemberName] string caller = "") | |
{ | |
Console.WriteLine("[{0}] {1}", caller, message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment