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.
SAE-2.01/MCTG/ConsoleApp/Menu/Entry.EntryStep.cs

72 lines
2.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
{
/// <summary>
/// Define a step of the Entry menu, or in other word, an entry itself.
/// </summary>
public class EntryStep
{
#region Attributes & Properties
private readonly Type _entryType;
/// <summary>
/// The entry description. This text is generally placed before the input field.
/// </summary>
public string Description { get; private set; }
/// <summary>
/// Contain the input gave by the menu.
/// </summary>
public string Input { get; internal set; }
#endregion
#region Constructors
/// <summary>
/// Constructor of the entry step.
/// </summary>
/// <param name="description">The text generally placed before the input in the menu.</param>
/// <param name="type">The type of the returned input.</param>
public EntryStep(string description, Type type)
{
Description = description;
Input = "";
_entryType = type;
}
#endregion
#region Methods
/// <summary>
/// Get the inputed string converted on this entry type.
/// </summary>
/// <returns>The converted string on the entry type.</returns>
/// <exception cref="NotImplementedException">Throw when the entry type converter does not exist here.</exception>
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
}
}
}