Use nameof instead of strongly typed string
MODIFY
WalletWasabi/Backend/Models/FilterModel.cs
WalletWasabi/Backend/Models/FilterModel.cs
@@ -87,7 +87,7 @@ namespace WalletWasabi.Backend.Models
}
else
{
- throw new FormatException("Could not parse Height.");
+ throw new FormatException($"Could not parse {nameof(Height)}.");
}
}

MODIFY
WalletWasabi/Mono/Option.cs
WalletWasabi/Mono/Option.cs
@@ -211,15 +211,15 @@ namespace Mono.Options
if (MaxValueCount == 0 && OptionValueType != OptionValueType.None)
{
throw new ArgumentException(
- "Cannot provide maxValueCount of 0 for OptionValueType.Required or " +
- "OptionValueType.Optional.",
+ $"Cannot provide {nameof(maxValueCount)} of 0 for {nameof(OptionValueType)}.{nameof(OptionValueType.Required)}" +
+ $" or {nameof(OptionValueType)}.{nameof(OptionValueType.Optional)}.",
nameof(maxValueCount));
}
if (OptionValueType == OptionValueType.None && maxValueCount > 1)
{
throw new ArgumentException(
- $"Cannot provide maxValueCount of {maxValueCount} for OptionValueType.None.",
+ $"Cannot provide {nameof(maxValueCount)} of {maxValueCount} for {nameof(OptionValueType)}.{nameof(OptionValueType.None)}.",
nameof(maxValueCount));
}
@@ -278,9 +278,7 @@ namespace Mono.Options
catch (Exception e)
{
throw new OptionException(
- string.Format(
- c.OptionSet.MessageLocalizer("Could not convert string `{0}' to type {1} for option `{2}'."),
- value, targetType.Name, c.OptionName),
+ string.Format(c.OptionSet.MessageLocalizer($"Could not convert string `{value}' to type {targetType.Name} for option `{c.OptionName}'.")),
c.OptionName, e);
}
return t;
@@ -300,7 +298,7 @@ namespace Mono.Options
string name = Names[i];
if (name.Length == 0)
{
- throw new ArgumentException("Empty option names are not supported.", "prototype");
+ throw new ArgumentException("Empty option names are not supported.", nameof(Prototype).ToLower());
}
int end = name.IndexOfAny(NameTerminator);
@@ -318,7 +316,7 @@ namespace Mono.Options
{
throw new ArgumentException(
$"Conflicting option types: '{type}' vs. '{name[end]}'.",
- "prototype");
+ nameof(Prototype).ToLower());
}
AddSeparators(name, end, seps);
@@ -333,7 +331,7 @@ namespace Mono.Options
{
throw new ArgumentException(
$"Cannot provide key/value separators for Options taking {MaxValueCount} value(s).",
- "prototype");
+ nameof(Prototype).ToLower());
}
if (MaxValueCount > 1)
@@ -367,7 +365,7 @@ namespace Mono.Options
{
throw new ArgumentException(
$"Ill-formed name/value separator found in \"{name}\".",
- "prototype");
+ nameof(Prototype).ToLower());
}
start = i + 1;
@@ -378,7 +376,7 @@ namespace Mono.Options
{
throw new ArgumentException(
$"Ill-formed name/value separator found in \"{name}\".",
- "prototype");
+ nameof(Prototype).ToLower());
}
seps.Add(name.Substring(start, i - start));
@@ -398,7 +396,7 @@ namespace Mono.Options
{
throw new ArgumentException(
$"Ill-formed name/value separator found in \"{name}\".",
- "prototype");
+ nameof(Prototype).ToLower());
}
}

MODIFY
WalletWasabi/Mono/OptionSet.cs
WalletWasabi/Mono/OptionSet.cs
@@ -196,7 +196,7 @@ namespace Mono.Options
{
if (item is null)
{
- throw new ArgumentNullException("option");
+ throw new ArgumentNullException(nameof(Option).ToLower());
}
if (item.Names != null && item.Names.Length > 0)
@@ -205,7 +205,7 @@ namespace Mono.Options
}
// This should never happen, as it's invalid for Option to be
// constructed w/o any names.
- throw new InvalidOperationException("Option has no names!");
+ throw new InvalidOperationException($"{nameof(Option)} has no names!");
}
[Obsolete("Use KeyedCollection.this[string]")]
@@ -294,13 +294,13 @@ namespace Mono.Options
// (see Option.ParsePrototype(), and thus it'll prevent Category
// instances from being accidentally used as normal options.
public Category(string description)
- : base("=:Category:= " + description, description)
+ : base($"=:{nameof(Category)}:= " + description, description)
{
}
protected override void OnParseComplete(OptionContext c)
{
- throw new NotSupportedException("Category.OnParseComplete should not be invoked.");
+ throw new NotSupportedException($"{nameof(Category)}.{nameof(OnParseComplete)} should not be invoked.");
}
}
@@ -692,7 +692,7 @@ namespace Mono.Options
}
throw new OptionException(string.Format(MessageLocalizer(
- "Cannot use unregistered option '{0}' in bundle '{1}'."), rn, f + n), null);
+ $"Cannot use unregistered option '{rn}' in bundle '{f + n}'.")), null);
}
p = this[rn];
switch (p.OptionValueType)
@@ -711,7 +711,7 @@ namespace Mono.Options
return true;
}
default:
- throw new InvalidOperationException("Unknown OptionValueType: " + p.OptionValueType);
+ throw new InvalidOperationException($"Unknown {nameof(OptionValueType)}: " + p.OptionValueType);
}
}
return true;
@@ -960,7 +960,7 @@ namespace Mono.Options
{
if ((i + 1) == description.Length || description[i + 1] != '}')
{
- throw new InvalidOperationException("Invalid option description: " + description);
+ throw new InvalidOperationException($"Invalid option description: {description}");
}
++i;

Use nameof instead of strongly typed string