
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Parsing Command-Line Parameters
|
173
This class overrides four methods of the ParseCmdLine class. The DisplayHelp method is
overridden to display the relevant information needed to correctly use the command-
line parameters in your application. The overloaded
DisplayErrorMsg methods are
overridden to prevent the lengthy exception message from being displayed. Finally,
the
ParseSwitch method is overridden to add some more preventive code that will
disallow any arguments from being added to a switch that should not have any argu-
ments. By overriding other methods in the
ParseCmdLine class, you can modify this
class to handle many other situations specific to your application.
public virtual void DisplayErrorMsg(string msg)
{
Console.WriteLine(
"An error has occurred while processing the command-line arguments:");
Console.WriteLine( );
FileVersionInfo version =
Process.GetCurrentProcess( ).MainModule.FileVersionInfo;
if (Process.GetCurrentProcess( ).ProcessName.Trim( ).Length > 0)
{
Console.WriteLine(Process.GetCurrentProcess( ).ProcessName);
}
else
{
Console.WriteLine("Product Name: " + version.ProductName);
}
Console.WriteLine("Version " + version.FileVersion);
Console.WriteLine("Copyright " + version.LegalCopyright);
Console.WriteLine("TradeMarks " + version.LegalTrademarks);
DisplayHelp( ...