You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConsoleApp.Menu
|
|
{
|
|
internal abstract partial class Entry
|
|
{
|
|
public class EntryStep
|
|
{
|
|
private Type _entryType;
|
|
|
|
public string Description { get; private set; }
|
|
public string? Input { get; private set; }
|
|
|
|
internal EntryStep(string description, Type type)
|
|
{
|
|
Description = description;
|
|
Input = null;
|
|
_entryType = type;
|
|
}
|
|
|
|
public object GetEntry()
|
|
{
|
|
Input = Console.ReadLine();
|
|
|
|
if (Input is null)
|
|
throw new ArgumentException("Error: input is null.");
|
|
|
|
try
|
|
{
|
|
if (_entryType == typeof(string))
|
|
return Input;
|
|
if (_entryType == typeof(int))
|
|
return Int32.Parse(Input);
|
|
if (_entryType == typeof(DateTime))
|
|
return DateTime.Parse(Input);
|
|
}
|
|
catch (FormatException fe)
|
|
{
|
|
Console.Error.WriteLine(fe);
|
|
}
|
|
|
|
throw new NotImplementedException("Error: parse of this type is not implemented.");
|
|
}
|
|
}
|
|
}
|
|
}
|