private static string getError(OutputMessages pMessages, Description pDescription, eERROR pError) { using (StringWriter sw = new StringWriter()) { Console.SetError(sw); pMessages.Error(pDescription, pError); return sw.ToString().Trim(); } }
/// <summary> /// Prints an error message that relates to the description. /// </summary> /// <param name="pDescs">Collection of parameter descriptions.</param> /// <param name="pError">Type of error being reported.</param> /// <returns>True if any errors reported.</returns> private bool Report(IEnumerable <Description> pDescs, eERROR pError) { bool result = false; foreach (Description desc in pDescs) { _messages.Error(desc, pError); result = true; } return(result); }
public void Error_1() { MockOutput mock = new MockOutput(); OutputMessages output = new OutputMessages(CliOptions.WindowsStyle, mock); Description desc = new Description("width", "The rectangle width", eROLE.NAMED, new ParamString(), eSCOPE.REQUIRED, eMULTIPLICITY.ONCE); const eERROR unsupported = (eERROR)(-1); output.Error(desc, unsupported); }
/// <summary> /// Called when a validation fails on the parameters. /// </summary> /// <param name="pDesc">The description of the failed parameter.</param> /// <param name="pError">The type of error.</param> public void Error(Description pDesc, eERROR pError) { switch (pError) { case eERROR.REQUIRED: _output.Error(OutputFormatter.WriteRequired(pDesc.Role, _options.Prefix, pDesc.Name)); return; case eERROR.DUPLICATE: _output.Error(OutputFormatter.WriteDuplicate(pDesc.Role, _options.Prefix, pDesc.Name)); return; case eERROR.MISSING_VALUE: _output.Error(OutputFormatter.WriteMissingValue(pDesc.Role, _options.Prefix, pDesc.Name)); return; } throw new InvalidArgumentException("Unsupported error type"); }
/// <summary> /// Prints an error message that relates to the description. /// </summary> /// <param name="pDescs">Collection of parameter descriptions.</param> /// <param name="pError">Type of error being reported.</param> /// <returns>True if any errors reported.</returns> private bool Report(IEnumerable<Description> pDescs, eERROR pError) { bool result = false; foreach (Description desc in pDescs) { _messages.Error(desc, pError); result = true; } return result; }
private static string getError(OutputMessages pMessages, Description pDescription, eERROR pError) { using (StringWriter sw = new StringWriter()) { Console.SetError(sw); pMessages.Error(pDescription, pError); return(sw.ToString().Trim()); } }