/// <summary> /// A convenience method that wraps <code>command.Wait()</code> in order to re-throw a fancy <see cref="CommandLineException"/> /// when the underlying task fails or is canceled. /// </summary> public static void WaitWithFancyError(this Command command, CommandLineErrorCode errorCode) { try { command.Wait(); } catch (Exception e) { Log.Ex(e); throw new CommandLineException(errorCode, e); } }
public CommandLineException(CommandLineErrorCode errorCode, Exception innerException) : base(errorCode.GetDefaultMessage(), innerException) { Code = errorCode; }
public CommandLineException(CommandLineErrorCode errorCode, string message) : base(message) { Code = errorCode; }
public CommandLineException(CommandLineErrorCode errorCode, string message, Exception innerException) : base(message, innerException) { Code = errorCode; }
public CommandLineException(CommandLineErrorCode errorCode) : base(errorCode.GetDefaultMessage()) { Code = errorCode; }
private static MemberInfo ForValue(CommandLineErrorCode code) { return(typeof(CommandLineErrorCode).GetField(Enum.GetName(typeof(CommandLineErrorCode), code))); }
private static CommandLineErrorCodeAttribute GetAttribute(CommandLineErrorCode code) { return((CommandLineErrorCodeAttribute)Attribute.GetCustomAttribute(ForValue(code), typeof(CommandLineErrorCodeAttribute))); }
public static string GetLocalizationKey(this CommandLineErrorCode code) { CommandLineErrorCodeAttribute attribute = (CommandLineErrorCodeAttribute)Cache[code]; return(attribute?.LocalizationKey); }
public static string GetDefaultMessage(this CommandLineErrorCode code) { CommandLineErrorCodeAttribute attribute = (CommandLineErrorCodeAttribute)Cache[code]; return(attribute != null ? attribute.DefaultMessage : string.Empty); }