C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Customising Output From Dump, Excluding some properties
sgmoore
post Jun 24 2009, 06:06 AM
Post #1


New Member
*

Group: Members
Posts: 9
Joined: 20-November 08
Member No.: 1,589



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.




Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jun 25 2009, 04:03 AM
Post #2


Advanced Member
******

Group: Members
Posts: 203
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



You can implement ICustomMemberProvider:

Would that help?

Joe
Go to the top of the page
 
+Quote Post
sgmoore
post Jun 26 2009, 12:11 AM
Post #3


New Member
*

Group: Members
Posts: 9
Joined: 20-November 08
Member No.: 1,589



QUOTE (JoeAlbahari @ Jun 25 2009, 04:03 AM) *
You can implement ICustomMemberProvider:

Would that help?

Joe


Yes it would, that works perfectly. Thank you very much.
(And apologies for not reading the FAQ.)

Stephen
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 7th November 2009 - 01:26 PM