namespace MPF.ExecutionContexts.Data
{
///
/// Represents a string flag with an optional trailing value
///
public class StringInput : Input
{
#region Constructors
///
public StringInput(string name)
: base(name) { }
///
public StringInput(string name, bool required)
: base(name, required) { }
///
public StringInput(string shortName, string longName)
: base(shortName, longName) { }
///
public StringInput(string shortName, string longName, bool required)
: base(shortName, longName, required) { }
#endregion
///
public override bool Process(string[] parts, ref int index)
{
// Check the parts array
if (parts.Length == 0)
return false;
// Check the index
if (index < 0 || index >= parts.Length)
return false;
// Check the name
if (parts[index] != Name && (_longName != null && parts[index] != _longName))
return false;
// Ensure the value exists
if (!DoesExist(parts, index + 1))
{
Value = _required ? null : string.Empty;
return !_required;
}
index++;
Value = parts[index];
return true;
}
}
}