Dump methods

May 9, 2012 at 7:37 PM

This looks like an interesting project.    As I was scanning through the source code, I had a few suggestion, mostly, as it turns out, to do with the Dump methods.

 public void Dump(StringBuilder sb)
 {
     sb.Append(this.DumpName + " " + this.Target.Name);
 }

1) If you are going to have a Dump method in many classes, then there should be a ICanDump interface which they implement.

2)  (this is see people doing all the time, and it really bugs me) Doing the string concatenation for the argument to the Append call, kinda defeats the purpose of using the StringBuilder in the first place.  That should be:

       sb.Append(this.DumpName);
       sb.Append(" ");
       sb.Append(this.Target.Name);

or

       sb.AppendFormat("{0} {1}. this.DumpName, this.Target.Name);

however....

3) While dumping to a StringBuilder is a good idea, you can get the same effect and more flexibility by using a TextWriter

 public void Dump(TextWriter tw)
 {
     tw.Write("{0} {1}. this.DumpName, this.Target.Name);
 }

Then you can use a StringWriter, and have it work just like the StringBuilder, or have it write to a disk file, or anything else the implements a TextWriter.