Skip to content

Instantly share code, notes, and snippets.

@MaxAtoms
Last active May 7, 2022 15:43
Show Gist options
  • Save MaxAtoms/9b9f14f7bab6d7ed7a64316d211d5f5d to your computer and use it in GitHub Desktop.
Save MaxAtoms/9b9f14f7bab6d7ed7a64316d211d5f5d to your computer and use it in GitHub Desktop.
Trying out C# Caller Attributes
public static class CallerAttributeExtensions
{
public static void WriteCallerAttributeValuesToConsole<T>( this T? obj,
[CallerMemberName] string? member = null,
[CallerFilePath] string? filePath = null,
[CallerLineNumber] int lineNum = 0,
[CallerArgumentExpression("obj")] string? expr = null )
{
Console.Out.WriteLine( $"{member} {filePath} {lineNum} {expr}" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment