mini nonbehavior modifying refactoring
MODIFY
WalletWasabi/Http/Models/HeaderField.cs
WalletWasabi/Http/Models/HeaderField.cs
@@ -57,7 +57,7 @@ namespace WalletWasabi.Http.Models
using var reader = new StringReader(fieldString);
var name = reader.ReadPart(':');
// if empty
- if (name is null || name.Trim() == "")
+ if (string.IsNullOrEmpty(name?.Trim()))
{
throw new FormatException($"Wrong {nameof(HeaderField)}: {fieldString}.");
}

MODIFY
WalletWasabi/Http/Models/RequestLine.cs
WalletWasabi/Http/Models/RequestLine.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Http.Models
Method = method;
// https://tools.ietf.org/html/rfc7230#section-2.7.1
// A sender MUST NOT generate an "http" URI with an empty host identifier.
- if (uri.DnsSafeHost == "")
+ if (string.IsNullOrEmpty(uri.DnsSafeHost))
{
throw new HttpRequestException("Host identifier is empty.");
}

MODIFY
WalletWasabi/Hwi/Parsers/HwiParser.cs
WalletWasabi/Hwi/Parsers/HwiParser.cs
@@ -78,7 +78,7 @@ namespace WalletWasabi.Hwi.Parsers
{
error = new HwiException(code.Value, err);
}
- else if (err != "")
+ else if (err.Length != 0)
{
error = new HwiException(HwiErrorCode.UnknownError, err);
}

MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -122,15 +122,15 @@ namespace WalletWasabi.Logging
return;
}
- message = string.IsNullOrWhiteSpace(message) ? "" : message;
+ message = Guard.Correct(message);
var category = string.IsNullOrWhiteSpace(callerFilePath) ? "" : $"{ExtractFileName(callerFilePath)} ({callerLineNumber})";
var messageBuilder = new StringBuilder();
messageBuilder.Append($"{DateTime.UtcNow.ToLocalTime():yyyy-MM-dd HH:mm:ss} {level.ToString().ToUpperInvariant()}\t");
- if (message == "")
+ if (message.Length == 0)
{
- if (category == "") // If both empty. It probably never happens though.
+ if (category.Length == 0) // If both empty. It probably never happens though.
{
messageBuilder.Append($"{EntrySeparator}");
}
@@ -141,7 +141,7 @@ namespace WalletWasabi.Logging
}
else
{
- if (category == "") // If only the category is empty.
+ if (category.Length == 0) // If only the category is empty.
{
messageBuilder.Append($"{message}{EntrySeparator}");
}

MODIFY
WalletWasabi/Models/ConcurrentHashSet.cs
WalletWasabi/Models/ConcurrentHashSet.cs
@@ -345,7 +345,7 @@ namespace WalletWasabi.Models
}
current = current.Next;
}
- return default(T);
+ return default;
}
/// <summary>

MODIFY
WalletWasabi/Models/Height.cs
WalletWasabi/Models/Height.cs
@@ -64,7 +64,7 @@ namespace WalletWasabi.Models
height = default;
var correct = Guard.Correct(heightOrHeightType);
- if (correct == "")
+ if (correct.Length == 0)
{
return false;
}

MODIFY
WalletWasabi/Models/SmartLabel.cs
WalletWasabi/Models/SmartLabel.cs
@@ -25,7 +25,7 @@ namespace WalletWasabi.Models
Labels = labels
.SelectMany(x => x?.Split(Separators, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>())
.Select(x => x.Trim())
- .Where(x => x != "")
+ .Where(x => x.Length != 0)
.Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(x => x)
.ToArray();

MODIFY
WalletWasabi/Mono/Option.cs
WalletWasabi/Mono/Option.cs
@@ -159,6 +159,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
+using WalletWasabi.Helpers;
namespace Mono.Options
{
@@ -176,20 +177,8 @@ namespace Mono.Options
protected Option(string prototype, string description, int maxValueCount, bool hidden)
{
- if (prototype is null)
- {
- throw new ArgumentNullException(nameof(prototype));
- }
-
- if (prototype == "")
- {
- throw new ArgumentException("Cannot be an empty string.", nameof(prototype));
- }
-
- if (maxValueCount < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxValueCount));
- }
+ Guard.NotNullOrEmptyOrWhitespace(nameof(prototype), prototype);
+ Guard.MinimumAndNotNull(nameof(maxValueCount), maxValueCount, 0);
Prototype = prototype;
Description = description;
@@ -296,7 +285,7 @@ namespace Mono.Options
for (int i = 0; i < Names.Length; ++i)
{
string name = Names[i];
- if (name == "")
+ if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("Empty option names are not supported.", nameof(Prototype));
}
@@ -342,7 +331,7 @@ namespace Mono.Options
{
ValueSeparators = new string[] { ":", "=" };
}
- else if (seps.Count == 1 && seps[0] == "")
+ else if (seps.Count == 1 && string.IsNullOrEmpty(seps[0]))
{
ValueSeparators = null;
}

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -1022,7 +1022,7 @@ namespace WalletWasabi.Services
coinWaitingForMix.Secret = null;
CoinDequeued?.Invoke(this, coinWaitingForMix);
var correctReason = Guard.Correct(reason);
- var reasonText = correctReason != "" ? $" Reason: {correctReason}" : "";
+ var reasonText = correctReason.Length != 0 ? $" Reason: {correctReason}" : "";
Logger.LogInfo($"Coin dequeued: {coinWaitingForMix.Index}:{coinWaitingForMix.TransactionId}.{reasonText}.");
}

MODIFY
WalletWasabi/Services/ExtPubKeyExplorer.cs
WalletWasabi/Services/ExtPubKeyExplorer.cs
@@ -8,7 +8,7 @@ using WalletWasabi.Backend.Models;
namespace WalletWasabi.Services
{
- public class ExtPubKeyExplorer
+ public static class ExtPubKeyExplorer
{
/// <summary>
/// WARNING: ONLY CHECKS CONFIRMED KEYPATHS

mini nonbehavior modifying refactoring