Home

Global ToDump hook is not working

I am trying the global ToDump hook in "My Extensions" and it is only working inside "My Extensions" but not other queries. My LinqPad version is v5.36.03 (AnyCPU).

Thanks

Comments

  • Never mind, looks like caching issue, after restarting LinqPad it worked.
  • edited February 23

    I tried this example from https://linqpad.net/CustomizingDump.aspx, but it doesn't work (also not after a restart of LinqPad).
    I'm using LINQPad 7 premium edition v7.2.7 (x64).

    Dump still dumps all properties, including BirthDate. static object ToDump() is never called (as can be checked with the Console.WriteLine line).

    Am i missing something?

    public class Customer
    {
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
    }

    void Main()
    {
    // You can test your ToDump here by dumping a Customer object.
    // Notice that we just Dump it (LINQPad finds the ToDump method itself).
    new Customer { FirstName = "Joe", LastName = "Bloggs" }.Dump();
    "Main".Dump(); // test where the output goes
    }

    public static class MyExtensions
    {
    }

    // Define a top-level method called ToDump (outside the MyExtensions class):
    static object ToDump(object input)
    {
    var customer = input as Customer;
    "ToDump()".Dump();
    if (customer != null)
    return new { customer.FirstName, customer.LastName };

    return input;
    

    }

  • I would guess you have all this in your main query. The static object ToDump(object input) method needs to be in "My Extensions" and because it references Customer, that class has to be defined there as well.

  • Thank you sgmoore for your reaction.
    Your suggestion is however in contrast with the comment in the example (from linqpad.net) that says: // Define a top-level method called ToDump (outside the MyExtensions class).
    I'm looking for a way to get this top-level method working as explained here: https://linqpad.net/CustomizingDump.aspx

  • The comment // Define a top-level method called ToDump (outside the MyExtensions class) is perhaps unclear. You need to define the method outside (above or below) the MyExtensions class, but still within the My Extensions query.

    Nonetheless, it's limiting that the static ToDump method works only in My Extensions. I'll see what I can do to fix this.

  • The latest build now lets you define a static ToDump method in any query:
    https://www.linqpad.net/linqpad7.aspx#beta

Sign In or Register to comment.