Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created July 27, 2017 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicFinn/9388573e32d771579c48c927983c1c45 to your computer and use it in GitHub Desktop.
Save DominicFinn/9388573e32d771579c48c927983c1c45 to your computer and use it in GitHub Desktop.
These are useful attributes, especially when logging info messages. Caveat. I haven't looked into how much these cost to call...
using System;
using System.Runtime.CompilerServices;
namespace ReflectionInfo
{
class Program
{
static void LogMessage(
string logMessage,
[CallerFilePath] string callingFilePath = null,
[CallerMemberName] string callingMember = null,
[CallerLineNumber] int callingLineNumber = 0
)
{
Console.WriteLine($"{logMessage}, " +
$"Information {Environment.NewLine} " +
$"FilePath: {callingFilePath} \n" +
$"Member: {callingMember} \n" +
$"Line Number: {callingLineNumber}");
}
static void Main(string[] args)
{
LogMessage("Log this cool story bro");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment