Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MoreNET.Utils
- {
- public static class BaseType
- {
- public static Byte ReadByte(string prompt = "")
- {
- Console.Write(prompt);
- return Byte.Parse(Console.ReadLine());
- }
- public static Byte ReadByte<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Byte.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static Byte ReadByte<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Byte.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static Byte ReadByte<TException>(Func<Byte> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Byte.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static Byte ReadByte<TException>(Func<string, Byte> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Byte.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static SByte ReadSByte(string prompt = "")
- {
- Console.Write(prompt);
- return SByte.Parse(Console.ReadLine());
- }
- public static SByte ReadSByte<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return SByte.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static SByte ReadSByte<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return SByte.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static SByte ReadSByte<TException>(Func<SByte> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return SByte.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static SByte ReadSByte<TException>(Func<string, SByte> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return SByte.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static Int16 ReadInt16(string prompt = "")
- {
- Console.Write(prompt);
- return Int16.Parse(Console.ReadLine());
- }
- public static Int16 ReadInt16<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Int16.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static Int16 ReadInt16<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Int16.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static Int16 ReadInt16<TException>(Func<Int16> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Int16.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static Int16 ReadInt16<TException>(Func<string, Int16> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Int16.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static UInt16 ReadUInt16(string prompt = "")
- {
- Console.Write(prompt);
- return UInt16.Parse(Console.ReadLine());
- }
- public static UInt16 ReadUInt16<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return UInt16.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static UInt16 ReadUInt16<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return UInt16.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static UInt16 ReadUInt16<TException>(Func<UInt16> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return UInt16.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static UInt16 ReadUInt16<TException>(Func<string, UInt16> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return UInt16.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static Int32 ReadInt32(string prompt = "")
- {
- Console.Write(prompt);
- return Int32.Parse(Console.ReadLine());
- }
- public static Int32 ReadInt32<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Int32.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static Int32 ReadInt32<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Int32.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static Int32 ReadInt32<TException>(Func<Int32> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Int32.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static Int32 ReadInt32<TException>(Func<string, Int32> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Int32.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static UInt32 ReadUInt32(string prompt = "")
- {
- Console.Write(prompt);
- return UInt32.Parse(Console.ReadLine());
- }
- public static UInt32 ReadUInt32<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return UInt32.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static UInt32 ReadUInt32<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return UInt32.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static UInt32 ReadUInt32<TException>(Func<UInt32> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return UInt32.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static UInt32 ReadUInt32<TException>(Func<string, UInt32> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return UInt32.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static Int64 ReadInt64(string prompt = "")
- {
- Console.Write(prompt);
- return Int64.Parse(Console.ReadLine());
- }
- public static Int64 ReadInt64<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Int64.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static Int64 ReadInt64<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Int64.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static Int64 ReadInt64<TException>(Func<Int64> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return Int64.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static Int64 ReadInt64<TException>(Func<string, Int64> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return Int64.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static UInt64 ReadUInt64(string prompt = "")
- {
- Console.Write(prompt);
- return UInt64.Parse(Console.ReadLine());
- }
- public static UInt64 ReadUInt64<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return UInt64.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- handler();
- return default;
- }
- }
- public static UInt64 ReadUInt64<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return UInt64.Parse(input);
- }
- catch (TException)
- {
- handler(input);
- return default;
- }
- }
- public static UInt64 ReadUInt64<TException>(Func<UInt64> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- try
- {
- return UInt64.Parse(Console.ReadLine());
- }
- catch (TException)
- {
- return handler();
- }
- }
- public static UInt64 ReadUInt64<TException>(Func<string, UInt64> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- try
- {
- return UInt64.Parse(input);
- }
- catch (TException)
- {
- return handler(input);
- }
- }
- public static Char ReadChar(string prompt = "")
- {
- Console.Write(prompt);
- return Console.ReadKey(true).KeyChar;
- }
- public static Char ReadChar<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- return Console.ReadKey(true).KeyChar;
- }
- public static Char ReadChar<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadKey(true).KeyChar;
- return Console.ReadKey(true).KeyChar;
- }
- public static Char ReadChar<TException>(Func<Char> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- return Console.ReadKey(true).KeyChar;
- }
- public static Char ReadChar<TException>(Func<string, Char> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadKey(true).KeyChar;
- return Console.ReadKey(true).KeyChar;
- }
- public static String ReadString(string prompt = "")
- {
- Console.Write(prompt);
- return Console.ReadLine();
- }
- public static String ReadString<TException>(Action handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- return Console.ReadLine();
- }
- public static String ReadString<TException>(Action<string> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- return Console.ReadLine();
- }
- public static String ReadString<TException>(Func<String> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- return Console.ReadLine();
- }
- public static String ReadString<TException>(Func<string, String> handler, string prompt = "")
- where TException : Exception
- {
- Console.Write(prompt);
- var input = Console.ReadLine();
- return Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement