advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Download the code for this article
Did you find this code useful? Do you agree that parsing is a generic operation, or is the setup required for a generic parser more trouble than it's worth? Is there anything missing from the sample parser that you feel would help developers write command-line parsing code? Let us know in the vb.dotnet.technical discussion group.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
Average Rating: 3/5 | Rate this item | 40 users have rated this item.
Parse and Validate Command Line Parameters with VB.NET (cont'd)
Extending the Sample Parser
You could alter or extend the sample parser to in several ways. For example, you could define individual CommandLineEntry subclasses for each type and eliminate the long Case structure in the ValidateValue method. You could create Exception classes inherited from ApplicationException to simplify the process of checking the errors. That would also make it easier to remove the error messages from the code and put them in localizable resource files. You could add a Number type that would convert the string entries to a designated numeric type and format, using a Min and Max property to verify that the entry lies within a specific range. The Min and Max properties would be useful for date types as well.
advertisement


Finally, as implemented, the parser doesn't fail immediately when it encounters a condition that causes an overall parse failure; instead, it simply adds error messages to the Errors collection. While that causes the parser to be slower when an error occurs early in the command line, it also gives developers the greatest possible amount of information about what the parser is doing. In addition, the sample code is not highly optimized—you can probably find numerous ways to make it faster.

Previous Page: Setting Up the Sample Parser  


A. Russell Jones is DevX's Executive Editor. He's a former reptile keeper and professional musician who now composes computer applications. His most recent books are Mastering ASP.NET with VB.NET and Mastering ASP.NET with Visual C# (both published by Sybex). Reach him by e-mail at rjones@devx.com.
Page 1: IntroductionPage 3: Setting Up the Sample Parser
Page 2: How the Command-Line Parser WorksPage 4: Extending the Sample Parser
Please rate this item (5=best)
 1  2  3  4  5
advertisement