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
Thanks
Comments
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 };
}
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) theMyExtensions
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
Not working for me, my query only contains the below code and prints "text" expected "1":
using v7.6.6 (X64)
Change the query type to "C# Program".
This won't work in C# Statements mode because the compiler munges local methods names.
Hmm... First it did not help to switch to "C# Program"
But apparently strings are a special case that do not go through ToDump()
other types seems work now