Skip to content

Settings and activity

1 result found

  1. 6 votes
    Vote

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    How important is this to you?

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)
    An error occurred while saving the comment
    Andrew Rutherfurd commented  · 

    Extended extension of the extension, lets you initialize line number:
    https://gist.github.com/AndrewR66/1aab13658e2a48586760a054e6b6beea

    An error occurred while saving the comment
    Andrew Rutherfurd commented  · 

    Great start, Mark Hurd,

    I have a simple extension of your extension:

    static class extensionMeth
    {
    static int offset=0;
    public static T DumpLine<T>(this T obj, string description = "", [CallerLineNumber]int lineNumber = 0)
    {
    if (offset == 0)
    offset = lineNumber-1;

    return obj.Dump($"Line:{lineNumber-offset}, {description}");
    }
    }

    // Usage:
    void Main()
    {
    "TestA".DumpLine("foo");

    "TestB".DumpLine("bar");
    "TestC".DumpLine();
    }

    Output, first DumpLine command gets line number 1:
    Line:1, foo
    TestA
    Line:3, bar
    TestB
    Line:4,
    TestC