/// <summary> /// Sets the ErrorCode and ErrorMesg values of an <see cref="IOptionObject"/>. /// </summary> /// <param name="optionObject"></param> /// <param name="errorCode"></param> /// <param name="errorMessage"></param> /// <returns></returns> public static IOptionObject SetErrorCodeAndMessage(IOptionObject optionObject, double errorCode = 0, string errorMessage = "") { if (optionObject == null) { throw new ArgumentNullException(nameof(optionObject), ScriptLinkHelpers.GetLocalizedString("parameterCannotBeNull", CultureInfo.CurrentCulture)); } if (!IsValidErrorCode(errorCode)) { throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("errorCodeIsNotValid", CultureInfo.CurrentCulture)); } if (errorCode == ErrorCode.OpenUrl && !ScriptLinkHelpers.IsValidUrl(errorMessage)) { throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("errorMessageIsNotValidUrl", CultureInfo.CurrentCulture)); } if (errorCode == ErrorCode.OpenForm && !IsValidOpenFormString(errorMessage)) { throw new ArgumentException(ScriptLinkHelpers.GetLocalizedString("errorMessageIsNotValidOpenForm", CultureInfo.CurrentCulture)); } optionObject.ErrorCode = errorCode; optionObject.ErrorMesg = errorMessage; return(optionObject); }