using System;
using System.Collections.Generic;
namespace QFSW.QC.Actions
{
///
/// Gets the next line of text entered into the console as a user response
/// and parses it to a value of the specified type.
///
public class ReadValue : Composite
{
private static readonly QuantumParser Parser = new QuantumParser();
/// A delegate which returns the parsed value entered by the user.
/// The config to provide the response flow with.
public ReadValue(Action getValue, ResponseConfig config)
: base(Generate(getValue, config))
{ }
/// A delegate which returns the parsed value entered by the user.
public ReadValue(Action getValue)
: this(getValue, ResponseConfig.Default)
{ }
private static IEnumerator Generate(Action getValue, ResponseConfig config)
{
string line = default;
yield return new ReadLine(t => line = t, config);
T value = Parser.Parse(line);
getValue(value);
}
}
}