using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp.Menu.Core
{
internal abstract partial class Entry
{
///
/// Define a step of the Entry menu, or in other word, an entry itself.
///
public class EntryStep
{
#region Attributes & Properties
private readonly Type _entryType;
///
/// The entry description. This text is generally placed before the input field.
///
public string Description { get; private set; }
///
/// Contain the input gave by the menu.
///
public string Input { get; internal set; }
#endregion
#region Constructors
///
/// Constructor of the entry step.
///
/// The text generally placed before the input in the menu.
/// The type of the returned input.
public EntryStep(string description, Type type)
{
Description = description;
Input = "";
_entryType = type;
}
#endregion
#region Methods
///
/// Get the inputed string converted on this entry type.
///
/// The converted string on the entry type.
/// Throw when the entry type converter does not exist here.
public object GetEntry()
{
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.");
}
#endregion
}
}
}