Thursday, December 15, 2005


Smart Paster plugin for Visual Studio

Shame on me for not posting about the Smart Paster 1.1 plugin before.

In Windows Forms applications I sometimes have to show long messages explaining why an operation failed or to provide additional information. The text is usually provided by the customer or a technical writer. Cutting and pasting it directly is normally not an option as:

  • the string is impossible to read in the editor or on paper when it is too long
  • there may be formatting characters which have to be escaped

XML and other text formats with quotes in them are even worse.

Unless you use Spart Paster that is;

The Smart Paster inserts the contents in a properly formatted String builder according to the configuration options:

Building XML the brutal way with string (i.e. not using XmlWriter) becomes a piece of cake. This source string in the clipboard:

 <node attribA="a" attribB="b"/>
 <path ="c:\temp\test.txt"/>

Automagically becomes this if you paste it as a StringBuilder called builder:

StringBuilder builder = new StringBuilder(81);
builder.AppendFormat(@"{0}", Environment.NewLine);
builder.AppendFormat(@"{0}{1}", ControlChars.Tab, Environment.NewLine);
builder.AppendFormat(@"{0}{1}", ControlChars.Tab, Environment.NewLine);
{0}", Environment.NewLine);

All quotes and strange characters taken care of. What more can you ask for?

No comments:

Post a Comment