I’ve been putting the finishing touches on a little command line utility, and wanted to add some nice instruction text etc.
Writing to the Console is certainly simple in .net, but line after line of Console.WriteLine gets old
Then I recalled some tricks using XML Literals in VB.net. A few snips later and I have this:
Private Shared Sub Header() Dim v = My.Application.Info.Version.ToString Dim x = <info> MyUtility v<%= v %> - Controller Tool (c) 2011 yadda yadda </info> Output(x.Value) End Sub
With that, I can enter any number of lines of text I need, I don’t have to worry about quotes or Console.Writeline’s, just a at the end of each line, and I can substitute in the app’s version number using the familiar ASP <%= notation (notice the variable ‘v’).
Now, if there was just a way to preserve whitespace in XML literals…