Skip to content

Instantly share code, notes, and snippets.

@AndrewR66
Last active February 4, 2017 14:49
Show Gist options
  • Save AndrewR66/1aab13658e2a48586760a054e6b6beea to your computer and use it in GitHub Desktop.
Save AndrewR66/1aab13658e2a48586760a054e6b6beea to your computer and use it in GitHub Desktop.
LinqPad Extension method that will include linenumbers in Dumps
public static class MyExtensions
{
static int offset = 0;
public static T DumpLine<T>(this T obj, string description = "", [CallerLineNumber]int lineNumber = 0)
{
if (description == "DumpLineInit")
{
try
{
offset = lineNumber - int.Parse(obj.ToString());
}
catch (Exception ex)
{
offset = lineNumber - 1;
Console.WriteLine("DumpLineInit failed:" + ex.ToString());
}
return obj;
}
return obj.Dump($"Line:{lineNumber - offset}, {description}");
}
}
// Usage
void Main()
{
26.DumpLine("DumpLineInit"); // Replace 26 with actual linenumber from linqpad
// this initializes linenumber count. No output from this statement.
"TestA".DumpLine("foo");
"TestB".DumpLine();
}
@AndrewR66
Copy link
Author

Example of Output:

image\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment