ConsoleLibraryHelper simplifies the capture of string, boolean, and number types from console users.
To use this library, add the "using ConsoleHelperLibrary" statement
You can request either a string, boolean, or number type.
Each of the 3 types have unique requirements you can place on the data you will be requesting. If data returned by user is invalid, it will state the error and prompt the user to try again.
Some requirement examples include a minimum or maximum string length or only allowing positive numbers. They can be used individually or chained together in any order you may like
"What is your first name: ".RequestStringFromConsole().WithNoSpaces().Close();
RequestStringFromConsole
WithMinLengthOf(int minLength)
WithMaxLengthOf(int maxLength)
WithNoSpaces()
WithNoSpecialCharacters()
WithNoNumbers()
WithOnlyTheseOptions(List<string> options)
"What is your age: ".RequestNumberFromConsole<int>.Close();
"How much money do you have: ".RequestNumberFromConsole<decimal>.WithOnlyPositives().Close();
RequestNumberFromConsole<T>
WithMinValueOf(T minimumValue)
WIthMaxValueOf(T maximumValue)
WithOnlyPositives()
WithOnlyNegatives()
Type T can be any of the following number types
- System.Boolean
- System.Byte
- System.Char
- System.Decimal
- System.Double
- System.SByte
- System.Single
- System.UInt16
- System.UInt32
- System.UInt64
"Are you over 18: ".RequestBoolFromConsole().Close();
The following rules are always true
- All methods extend objects of type string.
- All requirement methods begin with the keyword With
- i.e
WithNoSpaces()
,WithNoNumbers()
etc..
- i.e
- All request methods must end with a
.Close()
- An integer
- A positive number
- Greater than 5
- Less than 50
- No numbers
- No special characters
- No white spaces