First, Introduction
The console program is small, convenient and easy to develop. Generally, when I write a project, I am accustomed to writing a console client outside the intended client. This has several advantages:
(1) The amount of development is much less than the Web or GUI.
(2) It is simple to run and has few resources.
(3) Easy to track the operation of the program. For example, the use of log4net log, the Appender-ref set to Consoleappender, you can clearly see the system running track, in the use of Nhibernate/activerecord development is particularly convenient.
(4) When developing two different UI for the same system, it will consciously do the layering, so that the hierarchy structure of the system can be clearer and easy to maintain.
However, although the development of the console program is small, there are still some common functions to achieve more cumbersome. For example, here are a few questions:
(1) Enter the password. When the user enters the password, the console displays * * * instead of the password plaintext;
(2) The resolution and dispatch of the instruction. In the console, it is often necessary to input a pure string format instruction to the program, parse the instruction, parse the number of parameters, and invoke the corresponding method.
(3) Instructions of the Help system. Displays all instructions and their descriptions.
(4) Automatic completion of the instruction.
These problems are often encountered in the write console program, so I wrote two classes Consoleutil and Cmddispatcher, to achieve the above functions for reuse. Download code for this.
The code is written by c#3.0, and to be used in other C # versions, you need to make some changes.