예제 #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));
        }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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));
 }