Skip to content

Instantly share code, notes, and snippets.

@svick
Created October 9, 2014 08:29
Show Gist options
  • Save svick/97c6a8c8b006283c96e2 to your computer and use it in GitHub Desktop.
Save svick/97c6a8c8b006283c96e2 to your computer and use it in GitHub Desktop.
How to use caller info attributes on .Net 4.0
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