Exemple #1
0
        /// <summary>
        /// Invokes the opt 'RequestMessage()' and reads the next line from the console.
        /// Uses the Func to parse and validate the input and, if it returns null, a decision is made according to opt.
        /// </summary>
        /// <param name="opt"></param>
        /// <param name="parse"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T ReadInput <T>(IInputOptions opt, Func <string, T> parse)
        {
            opt.PrintRequestMsg();

            if (parse == null)
            {
                throw new ArgumentNullException("parse");
            }

            T result = parse(In.ReadLine());

            if (result != null)
            {
                return(result);
            }

            if (opt.ShowInvalidInputMsg)
            {
                opt.PrintInvalidInputMsg();
            }

            if (opt.RepeatWhenInvalid)
            {
                return(In.ReadInput <T>(opt, parse));
            }

            return(default(T));
        }
Exemple #2
0
 /// <summary>
 /// Returns 'ReadInput(IInputOptions opt, Func parse)'* with the specified parameters.
 /// If you don't specify the 'parse' parameter, it will automatically check for empty string<para/>
 /// * Invokes the opt 'RequestMessage()' and reads the next line from the console.
 /// Uses the Func to parse and validate the input and, if it returns null, a decision is made according to opt.<para/>
 /// - If you just want the raw string, use <c>In.ReadLine</c>
 /// </summary>
 /// <param name="opt"></param>
 /// <param name="parse">
 /// If null (default value), will be: '<c>(s) => string.IsNullOrWhiteSpace(s) ? null : s</c>'<para/>
 /// </param>
 /// <returns></returns>
 public static string ReadString(IInputOptions opt, Func <string, string> parse = null)
 {
     if (parse == null)
     {
         parse = s => string.IsNullOrWhiteSpace(s) ? null : s;
     }
     return(In.ReadInput <string>(opt, parse));
 }
Exemple #3
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to sbyte.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static sbyte?ReadSbyte(IInputOptions opt)
 {
     return(ReadInput <sbyte?>(opt, InputParser.ParseSbyte));
 }
Exemple #4
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to double.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static double?ReadDouble(IInputOptions opt)
 {
     return(ReadInput <double?>(opt, InputParser.ToDouble));
 }
Exemple #5
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to byte.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static byte?ReadByte(IInputOptions opt)
 {
     return(ReadInput <byte?>(opt, InputParser.ParseByte));
 }
Exemple #6
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to long.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static long?ReadLong(IInputOptions opt)
 {
     return(ReadInput <long?>(opt, InputParser.ToLong));
 }
Exemple #7
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to float.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static float?ReadFloat(IInputOptions opt)
 {
     return(ReadInput <float?>(opt, InputParser.ToFloat));
 }
Exemple #8
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to ulong.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static ulong?ReadUlong(IInputOptions opt)
 {
     return(ReadInput <ulong?>(opt, InputParser.ToUlong));
 }
Exemple #9
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to int.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static int?ReadInt(IInputOptions opt)
 {
     return(ReadInput <int?>(opt, InputParser.ToInt));
 }
Exemple #10
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to uint.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static uint?ReadUint(IInputOptions opt)
 {
     return(ReadInput <uint?>(opt, InputParser.ToUint));
 }
Exemple #11
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to short.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static short?ReadShort(IInputOptions opt)
 {
     return(ReadInput <short?>(opt, InputParser.ToShort));
 }
Exemple #12
0
 /// <summary>
 /// Invokes 'ReadInput' with the specified options and a parser to ushort.
 /// </summary>
 /// <param name="opt"></param>
 /// <returns></returns>
 public static ushort?ReadUshort(IInputOptions opt)
 {
     return(ReadInput <ushort?>(opt, InputParser.ToUshort));
 }