SystemExt/Terminal/ApplicationChooser.cs
/// <summary>
/// Prompt the user for the entry point to run and then run it.
/// </summary>
/// <param name="args">
/// Command line arguments.
/// </param>
/// <returns>
/// The code to terminate the application with on exit.
/// </returns>
Prompt the user for the entry point to run and then run it.
Prompt the user for the entry point to run and then run it .
public int Run(string[] args)
        {
            Console.WriteLine("Please choose the application you wish to run:");
            Console.WriteLine();
            for (var i = 0; i < this.EntryPoints.Count; i++)
                Console.WriteLine("  [{0}] {1}.", i, this.EntryPoints.ElementAt(i).Value);
            while (true)
            {
                Console.WriteLine();
                Console.Write("[{0}] => ", this.DefaultIndex);
                var input = Console.ReadLine();
                var index = -1;
                if (string.IsNullOrWhiteSpace(input))
                    index = this.DefaultIndex;
                if (index < 0 && (!int.TryParse(input, out index) || index < 0 || index >= this.EntryPoints.Count))
                {
                    Console.Error.WriteLine("You must enter a valid number between 0 and {0}.", this.EntryPoints.Count - 1);
                    continue;
                }
                return this.EntryPoints[index].Key(args);
            }
        }
public int Run ( string [ ] args ) { Console . WriteLine ( " " ) ; Console . WriteLine ( ) ; for ( var i = 0 ; i < this . EntryPoints . Count ; i ++ ) Console . WriteLine ( " " , i , this . EntryPoints . ElementAt ( i ) . Value ) ; while ( true ) { Console . WriteLine ( ) ; Console . Write ( " " , this . DefaultIndex ) ; var input = Console . ReadLine ( ) ; var index = - 1 ; if ( string . IsNullOrWhiteSpace ( input ) ) index = this . DefaultIndex ; if ( index < 0 && ( ! int . TryParse ( input , out index ) || index < 0 || index >= this . EntryPoints . Count ) ) { Console . Error . WriteLine ( " " , this . EntryPoints . Count - 1 ) ; continue ; } return this . EntryPoints [ index ] . Key ( args ) ; } }
Prompt the user for the entry point to run and then run it.
Prompt the user for the entry point to run and then run it .
// Display the possible entry points to the user. // Prompt the user to enter a value. // Read the value from the user. // If the value is empty then use the default. // If a value has been given ensure it is valid. // Call the entry point.
The code to terminate the application with on exit.
The code to terminate the application with on exit .
args
string[]
Command line arguments.
Command line arguments .