Last active
February 4, 2017 14:49
-
-
Save AndrewR66/1aab13658e2a48586760a054e6b6beea to your computer and use it in GitHub Desktop.
LinqPad Extension method that will include linenumbers in Dumps
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
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of Output:
\