Use c# 7 pattern matching to merge type check and cast
MODIFY
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
@@ -74,17 +74,17 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public void SelectLoadWallet()
{
- SelectedCategory = Categories.First(x => x is LoadWalletViewModel && (((LoadWalletViewModel)x).LoadWalletType == LoadWalletType.Desktop));
+ SelectedCategory = Categories.First(x => x is LoadWalletViewModel model && model.LoadWalletType == LoadWalletType.Desktop);
}
public void SelectTestPassword()
{
- SelectedCategory = Categories.First(x => x is LoadWalletViewModel && (((LoadWalletViewModel)x).LoadWalletType == LoadWalletType.Password));
+ SelectedCategory = Categories.First(x => x is LoadWalletViewModel model && model.LoadWalletType == LoadWalletType.Password);
}
public void SelectHardwareWallet()
{
- SelectedCategory = Categories.First(x => x is LoadWalletViewModel && (((LoadWalletViewModel)x).LoadWalletType == LoadWalletType.Hardware));
+ SelectedCategory = Categories.First(x => x is LoadWalletViewModel model && model.LoadWalletType == LoadWalletType.Hardware);
}
public ViewModelBase CurrentView

MODIFY
WalletWasabi/KeyManagement/HdPubKey.cs
WalletWasabi/KeyManagement/HdPubKey.cs
@@ -116,7 +116,7 @@ namespace WalletWasabi.KeyManagement
#region Equality
- public override bool Equals(object obj) => obj is HdPubKey && this == (HdPubKey)obj;
+ public override bool Equals(object obj) => obj is HdPubKey pubKey && this == pubKey;
public bool Equals(HdPubKey other) => this == other;

MODIFY
WalletWasabi/Models/SmartTransaction.cs
WalletWasabi/Models/SmartTransaction.cs
@@ -130,7 +130,7 @@ namespace WalletWasabi.Models
public bool Equals(Transaction other) => GetHash().Equals(other?.GetHash());
public override bool Equals(object obj) =>
- (obj is SmartTransaction && this == (SmartTransaction)obj);
+ obj is SmartTransaction transaction && this == transaction;
public override int GetHashCode() => GetHash().GetHashCode();

MODIFY
WalletWasabi/Nito/AsyncEx/AsyncMutex.cs
WalletWasabi/Nito/AsyncEx/AsyncMutex.cs
@@ -117,8 +117,8 @@ namespace Nito.AsyncEx
/// <param name="cancellationTokenObj"></param>
private void HoldLock(object cancellationTokenObj)
{
- CancellationToken ct = cancellationTokenObj is CancellationToken ?
- (CancellationToken)cancellationTokenObj :
+ CancellationToken ct = cancellationTokenObj is CancellationToken token ?
+ token :
CancellationToken.None;
while (true)

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -1081,9 +1081,8 @@ namespace WalletWasabi.Services
catch (Exception ex)
{
Logger.LogError<CcjClient>("Couldn't dequeue all coins. Some coins will likely be banned from mixing.");
- if (ex is AggregateException)
+ if (ex is AggregateException aggrEx)
{
- var aggrEx = ex as AggregateException;
foreach (var innerEx in aggrEx.InnerExceptions)
{
Logger.LogError<CcjClient>(innerEx);

Use c# 7 pattern matching to merge type check and cast