Changing dumped property names
Hi,
Does anyone know if there's an in the box method of changing dumped property names to include using things like the period character?
My use case is that I often create info type classes on a per query basis and might throw in properties from other different classes.
In this situation I'd like to add a period in the property name when it's dumped.
For example, if you want to dump SectionInfo with 'SectionCount' split with a period:
public class SectionInfo { public int SectionCount { get; set; } } new SectionInfo(){SectionCount = 2}.Dump();
Then the output might look like this:
I tried the DisplayName attribute but ideally I'd pass some mapping options to Dump particularly if you don't own the original class.
Maybe something like:
new SectionInfo(){SectionCount = 2}.Dump(MemberNameMap({"SectionCount", "Section.Count"}));
I'm still using LINQPad 5 and 7 together so ideally it would appear in both
Best regards
John
Comments
It's a hack, but you could do something like the following
As you can see from the results below, it works with single objects and lists etc and only changes the header/column names.
Works with LinqPad 5 and 7.
I've done something similar where I wanted to insert spaces and a
<br />
tag in some column names to make a report look better.You could use an expando. Here are a couple of examples:
Perfect. Thanks very much to you both.
I've borrowed from both of your approaches:
...which produces:
Thank you also, SGM, for highlighting
Util.CreateXhtmlWriter()
which I will definitely use in the future!Best regards
John
Having said that.... my example doesn't work everywhere, or indeed for nesting. When trying to use this on
Util.Dif
you just get an MemberDifNode (?) back as an expando so at the moment I'm jumping back out if it's an IDifResult.For nesting the SGM method has the advantage of going through all of the output and does pick up nested members.
Will think on this some more.
Why not respect System.ComponentModel.DataAnnotations.DisplayAttribute?
(also, DisplayFormatAttribute could be useful)