private static void UpdateHandler(ArgumentHandler handler, string value, string arg) { try { handler.Assign(value); } catch (ArgumentException ex) { throw new ProgrammerErrorException(ex.Message); } catch (NotSupportedException ex) { throw new InvalidValueException($"Wrong value type for argument \"{arg}\": {ex.Message}"); } catch (GetOptException) { throw; } catch (TargetInvocationException ex) { switch (ex.InnerException) { case GetOptException _: throw ex.InnerException; case NotSupportedException _: throw new InvalidValueException($"Wrong value type for argument \"{arg}\": {ex.Message}"); default: throw new ArgumentException(ex.Message, ex); } } /*catch (Exception ex) { * throw new ProgrammingErrorException(ex.Message, ex); * }*/ }
private static void UpdateHandler(ArgumentHandler handler, string value, string arg) { try { handler.Assign(value); } catch (ArgumentException ex) { throw new ProgrammingError(ex.Message); } catch (NotSupportedException ex) { throw new InvalidValueException(String.Format(CultureInfo.CurrentCulture, "Wrong value type for argument \"{0}\": {1}", arg, ex.Message)); } catch (GetOptException) { throw; } catch (TargetInvocationException ex) { if (ex.InnerException is GetOptException) { throw ex.InnerException; } if (ex.InnerException is NotSupportedException) { throw new InvalidValueException(String.Format(CultureInfo.CurrentCulture, "Wrong value type for argument \"{0}\": {1}", arg, ex.Message)); } throw new ProgrammingError(ex.Message); } catch (Exception ex) { throw new ProgrammingError(ex.Message); } }
private void ProcessAliases(MemberInfo info, ArgumentHandler handler) { var aliases = info.GetAttributes <ArgumentAliasAttribute>(); foreach (var alias in aliases) { string an = alias.Alias; if (opts.CaseType == ArgumentCaseType.Insensitive || opts.CaseType == ArgumentCaseType.OnlyLower) { an = an.ToLower(); } if (longs.ContainsKey(an)) { throw new ArgumentException($"Duplicate alias argument {an}"); } longs.Add(an, handler); } var shortAliases = info.GetAttributes <ShortArgumentAliasAttribute>(); foreach (string an in shortAliases.Select(a => a.Alias)) { if (shorts.ContainsKey(an)) { throw new ArgumentException($"Duplicate short argument {an}"); } shorts.Add(an, handler); } }
private static void UpdateHandler(ArgumentHandler handler, string value, string arg) { try { handler.Assign(value); } catch (ArgumentException ex) { throw new ProgrammingError(ex.Message); } catch (NotSupportedException ex) { throw new InvalidValueException(String.Format(CultureInfo.CurrentCulture, "Wrong value type for argument \"{0}\": {1}", arg, ex.Message)); } catch (GetOptException) { throw; } catch (TargetInvocationException ex) { if (ex.InnerException is GetOptException) { throw ex.InnerException; } if (ex.InnerException is NotSupportedException) { throw new InvalidValueException(String.Format(CultureInfo.CurrentCulture, "Wrong value type for argument \"{0}\": {1}", arg, ex.Message)); } throw new ProgrammingError(ex.Message); } catch (Exception ex) { throw new ProgrammingError(ex.Message); } }
private void ProcessAliases(MemberInfo info, ArgumentHandler ai) { foreach (ArgumentAlias alias in info.GetCustomAttributes(typeof(ArgumentAlias), true)) { var an = alias.Alias; if (opts.CaseType == ArgumentCaseType.Insensitive || opts.CaseType == ArgumentCaseType.OnlyLower) { an = an.ToLower(); } if (longs.ContainsKey(an)) { throw new ProgrammingError(String.Format("Duplicate alias argument {0}", an)); } longs.Add(an, ai); } foreach (ShortArgumentAlias sa in info.GetCustomAttributes(typeof(ShortArgumentAlias), true)) { var an = sa.Alias; if (shorts.ContainsKey(an)) { throw new ProgrammingError(String.Format("Duplicate short argument {0}", an)); } shorts.Add(an, ai); } }
private void ProcessShortArguments(MemberInfo info, ArgumentHandler ai) { foreach (ShortArgument sa in info.GetCustomAttributes(typeof(ShortArgument), true)) { var an = sa.Arg; if (shorts.ContainsKey(an)) { throw new ProgrammingError(String.Format("Duplicate short argument {0}", an)); } shorts.Add(an, ai); } }
private void ProcessShortArguments(MemberInfo info, ArgumentHandler handler) { var shortArguments = info.GetAttributes <ShortArgumentAttribute>(); foreach (string an in shortArguments.Select(a => a.Arg)) { if (shorts.ContainsKey(an)) { throw new ArgumentException($"Duplicate short argument {an}"); } shorts.Add(an, handler); } }
internal RequiredOptionMissingException(ArgumentHandler aOption) : this(String.Format(CultureInfo.CurrentCulture, "Required option {0} wasn't specified", aOption.Name.ToLower())) { }
internal RequiredOptionMissingException(ArgumentHandler aOption) : this(String.Format(CultureInfo.CurrentCulture, "Required option {0} wasn't specified", aOption.Name.ToLower())) { }
private void ProcessShortArguments(MemberInfo info, ArgumentHandler ai) { foreach (ShortArgument sa in info.GetCustomAttributes(typeof(ShortArgument), true)) { var an = sa.Arg; if (shorts.ContainsKey(an)) { throw new ProgrammingError(String.Format("Duplicate short argument {0}", an)); } shorts.Add(an, ai); } }
private void ProcessAliases(MemberInfo info, ArgumentHandler ai) { foreach (ArgumentAlias alias in info.GetCustomAttributes(typeof(ArgumentAlias), true)) { var an = alias.Alias; if (opts.CaseType == ArgumentCaseType.Insensitive || opts.CaseType == ArgumentCaseType.OnlyLower) { an = an.ToLower(); } if (longs.ContainsKey(an)) { throw new ProgrammingError(String.Format("Duplicate alias argument {0}", an)); } longs.Add(an, ai); } foreach (ShortArgumentAlias sa in info.GetCustomAttributes(typeof(ShortArgumentAlias), true)) { var an = sa.Alias; if (shorts.ContainsKey(an)) { throw new ProgrammingError(String.Format("Duplicate short argument {0}", an)); } shorts.Add(an, ai); } }
internal RequiredOptionMissingException(ArgumentHandler aOption) : this($"Required option {aOption.Name.ToLower()} wasn't specified") { }
internal RequiredOptionMissingException(ArgumentHandler aOption) : this(String.Format("Required option {0} wasn't specified", aOption.Name.ToUpper())) { }