Use nameof instead of magic strings (GUI, Packager, Tests projects)
MODIFY
WalletWasabi.Gui/CommandLine/Daemon.cs
WalletWasabi.Gui/CommandLine/Daemon.cs
@@ -127,7 +127,7 @@ namespace WalletWasabi.Gui.CommandLine
}
finally
{
- Logger.LogInfo($"Daemon stopped.");
+ Logger.LogInfo($"{nameof(Daemon)} stopped.");
}
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -245,7 +245,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Label = Label.Trim(',', ' ').Trim();
if (!IsMax && string.IsNullOrWhiteSpace(Label))
{
- SetWarningMessage("Label is required.");
+ SetWarningMessage($"{nameof(Label)} is required.");
return;
}
@@ -278,7 +278,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
if (!Money.TryParse(AmountText, out Money amount) || amount == Money.Zero)
{
- SetWarningMessage($"Invalid amount.");
+ SetWarningMessage("Invalid amount.");
return;
}

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -139,15 +139,15 @@ namespace WalletWasabi.Gui
Config = new Config(Path.Combine(DataDir, "Config.json"));
await Config.LoadOrCreateDefaultFileAsync();
- Logger.LogInfo<Config>("Config is successfully initialized.");
+ Logger.LogInfo<Config>($"{nameof(Config)} is successfully initialized.");
#endregion ConfigInitialization
BitcoinStore = new BitcoinStore();
- var bstoreInitTask = BitcoinStore.InitializeAsync(Path.Combine(DataDir, "BitcoinStore"), Network);
+ var bstoreInitTask = BitcoinStore.InitializeAsync(Path.Combine(DataDir, $"{nameof(BitcoinStore)}"), Network);
var hwiInitTask = HwiProcessManager.InitializeAsync(DataDir, Network);
- var addressManagerFolderPath = Path.Combine(DataDir, "AddressManager");
- AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{Network}.dat");
+ var addressManagerFolderPath = Path.Combine(DataDir, $"{nameof(AddressManager)}");
+ AddressManagerFilePath = Path.Combine(addressManagerFolderPath, $"{nameof(AddressManager)}{Network}.dat");
var addrManTask = InitializeAddressManagerBehaviorAsync();
var blocksFolderPath = Path.Combine(DataDir, $"Blocks{Network}");
@@ -308,7 +308,7 @@ namespace WalletWasabi.Gui
if (Network == Network.RegTest)
{
AddressManager = new AddressManager();
- Logger.LogInfo<AddressManager>($"Fake {nameof(AddressManager)} is initialized on the RegTest.");
+ Logger.LogInfo<AddressManager>($"Fake {nameof(AddressManager)} is initialized on the {Network.RegTest}.");
}
else
{
@@ -431,9 +431,9 @@ namespace WalletWasabi.Gui
ChaumianClient.Start();
Logger.LogInfo("Start Chaumian CoinJoin service...");
- Logger.LogInfo("Starting WalletService...");
+ Logger.LogInfo($"Starting {nameof(WalletService)}...");
await WalletService.InitializeAsync(token);
- Logger.LogInfo("WalletService started.");
+ Logger.LogInfo($"{nameof(WalletService)} started.");
token.ThrowIfCancellationRequested();
WalletService.Coins.CollectionChanged += Coins_CollectionChanged;

MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
@@ -67,7 +67,7 @@ namespace WalletWasabi.Gui
{
Global.InitializeUiConfig(uiConfig);
Application.Current.Resources.AddOrReplace(Global.UiConfigResourceKey, Global.UiConfig);
- Logging.Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");
+ Logging.Logger.LogInfo<UiConfig>($"{Global.UiConfig} is successfully initialized.");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -160,7 +160,7 @@ namespace WalletWasabi.Gui
Global.UiConfig.Width = Width;
Global.UiConfig.Height = Height;
await Global.UiConfig.ToFileAsync();
- Logging.Logger.LogInfo<UiConfig>("UiConfig is saved.");
+ Logging.Logger.LogInfo<UiConfig>($"{Global.UiConfig} is saved.");
}
Hide();

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -82,12 +82,12 @@ namespace WalletWasabi.Gui
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
- Logger.LogWarning(e?.Exception, "UnobservedTaskException");
+ Logger.LogWarning(e?.Exception, $"{nameof(TaskScheduler.UnobservedTaskException)}");
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
- Logger.LogWarning(e?.ExceptionObject as Exception, "UnhandledException");
+ Logger.LogWarning(e?.ExceptionObject as Exception, $"{nameof(AppDomain.CurrentDomain.UnhandledException)}");
}
private static AppBuilder BuildAvaloniaApp()

MODIFY
WalletWasabi.Packager/NSubsys/NSubsysUtil.cs
WalletWasabi.Packager/NSubsys/NSubsysUtil.cs
@@ -14,8 +14,8 @@ namespace NSubsys
/// </summary>
public static bool ProcessFile(string exeFilePath)
{
- Console.WriteLine("NSubsys: Subsystem Changer for Windows PE files.");
- Console.WriteLine($"NSubsys: Target EXE {exeFilePath}.");
+ Console.WriteLine($"{nameof(NSubsys)}: Subsystem Changer for Windows PE files.");
+ Console.WriteLine($"{nameof(NSubsys)}: Target EXE {exeFilePath}.");
using (var peFile = new PeUtility(exeFilePath))
{
SubSystemType subsysVal;
@@ -27,12 +27,12 @@ namespace NSubsys
switch (subsysVal)
{
case PeUtility.SubSystemType.ImageSubSystemWindowsGui:
- Console.WriteLine("NSubsys: Executable file is already a Win32 App!");
+ Console.WriteLine($"{nameof(NSubsys)}: Executable file is already a Win32 App!");
return true;
case PeUtility.SubSystemType.ImageSubSystemWindowsCui:
- Console.WriteLine("NSubsys: Console app detected...");
- Console.WriteLine("NSubsys: Converting...");
+ Console.WriteLine($"{nameof(NSubsys)}: Console app detected...");
+ Console.WriteLine($"{nameof(NSubsys)}: Converting...");
var subsysSetting = BitConverter.GetBytes((ushort)SubSystemType.ImageSubSystemWindowsGui);
@@ -45,18 +45,18 @@ namespace NSubsys
{
peFile.Stream.Seek(subsysOffset, SeekOrigin.Begin);
peFile.Stream.Write(subsysSetting, 0, subsysSetting.Length);
- Console.WriteLine("NSubsys: Conversion Complete...");
+ Console.WriteLine($"{nameof(NSubsys)}: Conversion Complete...");
}
else
{
- Console.WriteLine("NSubsys: Can't write changes!");
- Console.WriteLine("NSubsys: Conversion Failed...");
+ Console.WriteLine($"{nameof(NSubsys)}: Can't write changes!");
+ Console.WriteLine($"{nameof(NSubsys)}: Conversion Failed...");
}
return true;
default:
- Console.WriteLine($"NSubsys: Unsupported subsystem number: {subsysVal}.");
+ Console.WriteLine($"{nameof(NSubsys)}: Unsupported subsystem number: {subsysVal}.");
return false;
}
}

MODIFY
WalletWasabi.Tests/P2pTests.cs
WalletWasabi.Tests/P2pTests.cs
@@ -50,8 +50,8 @@ namespace WalletWasabi.Tests
throw new NotSupportedException($"{nameof(Network)} not supported: {network}.");
}
- var addressManagerFolderPath = Path.Combine(Global.Instance.DataDir, "AddressManager");
- var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"AddressManager{network}.dat");
+ var addressManagerFolderPath = Path.Combine(Global.Instance.DataDir, $"{nameof(AddressManager)}");
+ var addressManagerFilePath = Path.Combine(addressManagerFolderPath, $"{nameof(AddressManager)}{network}.dat");
var blocksFolderPath = Path.Combine(Global.Instance.DataDir, "Blocks", network.ToString());
var connectionParameters = new NodeConnectionParameters();
AddressManager addressManager = null;
@@ -111,7 +111,7 @@ namespace WalletWasabi.Tests
{
if (times > 4200) // 7 minutes
{
- throw new TimeoutException($"Connection test timed out.");
+ throw new TimeoutException("Connection test timed out.");
}
await Task.Delay(100);
times++;

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -861,9 +861,9 @@ namespace WalletWasabi.Tests
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == activeOutput.Amount);
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
}
- Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
- Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -897,9 +897,9 @@ namespace WalletWasabi.Tests
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend - res.Fee, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
- Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
- Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -930,9 +930,9 @@ namespace WalletWasabi.Tests
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
- Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
- Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -963,9 +963,9 @@ namespace WalletWasabi.Tests
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
- Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
- Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -996,9 +996,9 @@ namespace WalletWasabi.Tests
Assert.Equal(receive, activeOutput.ScriptPubKey);
Assert.Equal(amountToSend, activeOutput.Amount);
Assert.Contains(res.Transaction.Transaction.Outputs, x => x.Value == changeOutput.Amount);
- Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
- Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"Change Output: {changeOutput.Amount.ToString(false, true)} {changeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -1061,9 +1061,9 @@ namespace WalletWasabi.Tests
Assert.Equal(res.SpentCoins.Count(), res.Transaction.Transaction.Inputs.Count);
Assert.Equal(receive, activeOutput.ScriptPubKey);
- Logger.LogInfo<RegTests>($"Fee: {res.Fee}");
- Logger.LogInfo<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogInfo<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogInfo<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogInfo<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogInfo<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogInfo<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogInfo<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -1137,9 +1137,9 @@ namespace WalletWasabi.Tests
Assert.Empty(res.OuterWalletOutputs);
Assert.Equal(receive, activeOutput.ScriptPubKey);
- Logger.LogDebug<RegTests>($"Fee: {res.Fee}");
- Logger.LogDebug<RegTests>($"FeePercentOfSent: {res.FeePercentOfSent} %");
- Logger.LogDebug<RegTests>($"SpendsUnconfirmed: {res.SpendsUnconfirmed}");
+ Logger.LogDebug<RegTests>($"{nameof(res.Fee)}: {res.Fee}");
+ Logger.LogDebug<RegTests>($"{nameof(res.FeePercentOfSent)}: {res.FeePercentOfSent} %");
+ Logger.LogDebug<RegTests>($"{nameof(res.SpendsUnconfirmed)}: {res.SpendsUnconfirmed}");
Logger.LogDebug<RegTests>($"Active Output: {activeOutput.Amount.ToString(false, true)} {activeOutput.ScriptPubKey.GetDestinationAddress(network)}");
Logger.LogDebug<RegTests>($"TxId: {res.Transaction.GetHash()}");
@@ -3302,7 +3302,7 @@ namespace WalletWasabi.Tests
await Task.Delay(1000);
if (times > 21)
{
- throw new TimeoutException("State.GetAllWaitingCoins() always empty.");
+ throw new TimeoutException($"{nameof(chaumianClient1.State)}.{nameof(chaumianClient1.State.GetAllWaitingCoins)}() always empty.");
}
times++;
}

Use nameof instead of magic strings (GUI, Packager, Tests projects)