Customising Output From Dump, Excluding some properties |
![]() ![]() |
Customising Output From Dump, Excluding some properties |
Jun 24 2009, 06:06 AM
Post
#1
|
|
|
|
I find Linqpad very handy for writing snippets of code not necessarily related to Linq and one of the very handy features is the Dump() extension. However sometimes the output can be quite verbose, especially when dumping a list of objects that happens to contain another object or list of objects.
Is there a way of customising the output of an object to exclude some columns. An example is, if I have a SQL table called Area which contains a 1:1 to a table called Country, then LinqToSql appears to create a property called CountryID and another called Country, but only the first property appears in the Dump. However, if I write code like this class Country { public int ID { get ; set; } public string Name { get ; set; } } class Area { public Area(string areaName, Country country) { Name = areaName; Country = country ; CountryID = country.ID; } public string Name { get ; set; } public int CountryID { get ; set; } public Country Country{ get ; set; } } void Main() { Country uk = new Country() { Name = "UK" , ID =1 } ; List<Area> areas = new List<Area>(); areas.Add(new Area("England" , uk)); areas.Add(new Area("Scotland" , uk)); areas.Add(new Area("Wales" , uk)); areas.Add(new Area("Northen Ireland", uk)); areas.Dump(); } The output from this is a lot less readable as the Country object is embedded in the output. Is there an attribute that can be added to a property to exclude it or can the Dump be customised/overwritten to do this? Thanks Stephen PS, I know that making Country internal or private would do this, but I don't want to do that. |
|
|
|
Jun 25 2009, 04:03 AM
Post
#2
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 203 Joined: 15-February 08 From: Perth, Australia Member No.: 90 |
|
|
|
|
Jun 26 2009, 12:11 AM
Post
#3
|
|
|
|
Yes it would, that works perfectly. Thank you very much. (And apologies for not reading the FAQ.) Stephen |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 7th November 2009 - 01:26 PM |