Add rule to prefer switch expression
MODIFY
.editorconfig
.editorconfig
@@ -106,6 +106,9 @@ dotnet_style_readonly_field = false:error
# use expression body for lambdas
csharp_style_expression_bodied_lambdas = true:error
+# IDE0066: Convert switch statement to expression
+csharp_style_prefer_switch_expression = true:error
+
# name all constant or static fields using PascalCase
dotnet_naming_rule.constant_or_static_fields_should_be_pascal_case.severity = error

MODIFY
WalletWasabi.Gui/Config.cs
WalletWasabi.Gui/Config.cs
@@ -347,21 +347,14 @@ namespace WalletWasabi.Gui
public int GetTargetLevel(TargetPrivacy target)
{
- switch (target)
- {
- case TargetPrivacy.None:
- return 0;
-
- case TargetPrivacy.Some:
- return PrivacyLevelSome;
-
- case TargetPrivacy.Fine:
- return PrivacyLevelFine;
-
- case TargetPrivacy.Strong:
- return PrivacyLevelStrong;
- }
- return 0;
+ return target switch
+ {
+ TargetPrivacy.None => 0,
+ TargetPrivacy.Some => PrivacyLevelSome,
+ TargetPrivacy.Fine => PrivacyLevelFine,
+ TargetPrivacy.Strong => PrivacyLevelStrong,
+ _ => 0
+ };
}
protected override bool TryEnsureBackwardsCompatibility(string jsonString)

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
@@ -130,26 +130,20 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _isSelected, value);
}
- public string ToolTip
- {
- get
- {
- switch (Status)
- {
- case SmartCoinStatus.Confirmed: return "This coin is confirmed.";
- case SmartCoinStatus.Unconfirmed: return "This coin is unconfirmed.";
- case SmartCoinStatus.MixingOnWaitingList: return "This coin is waiting for its turn to be coinjoined.";
- case SmartCoinStatus.MixingBanned: return $"The coordinator banned this coin from participation until {Model?.BannedUntilUtc?.ToString("yyyy - MM - dd HH: mm", CultureInfo.InvariantCulture)}.";
- case SmartCoinStatus.MixingInputRegistration: return "This coin is registered for coinjoin.";
- case SmartCoinStatus.MixingConnectionConfirmation: return "This coin is currently in Connection Confirmation phase.";
- case SmartCoinStatus.MixingOutputRegistration: return "This coin is currently in Output Registration phase.";
- case SmartCoinStatus.MixingSigning: return "This coin is currently in Signing phase.";
- case SmartCoinStatus.SpentAccordingToBackend: return "According to the Backend, this coin is spent. Wallet state will be corrected after confirmation.";
- case SmartCoinStatus.MixingWaitingForConfirmation: return "Coinjoining unconfirmed coins is not allowed, unless the coin is a coinjoin output itself.";
- default: return "This is impossible.";
- }
- }
- }
+ public string ToolTip => Status switch
+ {
+ SmartCoinStatus.Confirmed => "This coin is confirmed.",
+ SmartCoinStatus.Unconfirmed => "This coin is unconfirmed.",
+ SmartCoinStatus.MixingOnWaitingList => "This coin is waiting for its turn to be coinjoined.",
+ SmartCoinStatus.MixingBanned => $"The coordinator banned this coin from participation until {Model?.BannedUntilUtc?.ToString("yyyy - MM - dd HH: mm", CultureInfo.InvariantCulture)}.",
+ SmartCoinStatus.MixingInputRegistration => "This coin is registered for coinjoin.",
+ SmartCoinStatus.MixingConnectionConfirmation => "This coin is currently in Connection Confirmation phase.",
+ SmartCoinStatus.MixingOutputRegistration => "This coin is currently in Output Registration phase.",
+ SmartCoinStatus.MixingSigning => "This coin is currently in Signing phase.",
+ SmartCoinStatus.SpentAccordingToBackend => "According to the Backend, this coin is spent. Wallet state will be corrected after confirmation.",
+ SmartCoinStatus.MixingWaitingForConfirmation => "Coinjoining unconfirmed coins is not allowed, unless the coin is a coinjoin output itself.",
+ _ => "This is impossible."
+ };
public Money Amount => Model.Amount;

MODIFY
WalletWasabi.Gui/Converters/CoinStatusBorderBrushConverter.cs
WalletWasabi.Gui/Converters/CoinStatusBorderBrushConverter.cs
@@ -17,12 +17,12 @@ namespace WalletWasabi.Gui.Converters
{
if (value is SmartCoinStatus status)
{
- switch (status)
+ return status switch
{
- case SmartCoinStatus.Confirmed: return Brushes.Transparent;
- case SmartCoinStatus.Unconfirmed: return Brushes.Transparent;
- default: return Brushes.Black;
- }
+ SmartCoinStatus.Confirmed => Brushes.Transparent,
+ SmartCoinStatus.Unconfirmed => Brushes.Transparent,
+ _ => Brushes.Black
+ };
}
else
{

MODIFY
WalletWasabi.Gui/Converters/CoinStatusColorConverter.cs
WalletWasabi.Gui/Converters/CoinStatusColorConverter.cs
@@ -17,20 +17,20 @@ namespace WalletWasabi.Gui.Converters
{
if (value is SmartCoinStatus status)
{
- switch (status)
+ return status switch
{
- case SmartCoinStatus.Confirmed: return Brushes.Transparent;
- case SmartCoinStatus.Unconfirmed: return Brushes.Transparent;
- case SmartCoinStatus.MixingOnWaitingList: return Brushes.WhiteSmoke;
- case SmartCoinStatus.MixingBanned: return Brushes.IndianRed;
- case SmartCoinStatus.MixingInputRegistration: return Brushes.LimeGreen;
- case SmartCoinStatus.MixingConnectionConfirmation: return Brushes.DarkGreen;
- case SmartCoinStatus.MixingOutputRegistration: return Brushes.DarkGreen;
- case SmartCoinStatus.MixingSigning: return Brushes.DarkGreen;
- case SmartCoinStatus.SpentAccordingToBackend: return Brushes.IndianRed;
- case SmartCoinStatus.MixingWaitingForConfirmation: return Brushes.LightYellow;
- default: throw new NotSupportedException(); // Or rather not implemented?
- }
+ SmartCoinStatus.Confirmed => Brushes.Transparent,
+ SmartCoinStatus.Unconfirmed => Brushes.Transparent,
+ SmartCoinStatus.MixingOnWaitingList => Brushes.WhiteSmoke,
+ SmartCoinStatus.MixingBanned => Brushes.IndianRed,
+ SmartCoinStatus.MixingInputRegistration => Brushes.LimeGreen,
+ SmartCoinStatus.MixingConnectionConfirmation => Brushes.DarkGreen,
+ SmartCoinStatus.MixingOutputRegistration => Brushes.DarkGreen,
+ SmartCoinStatus.MixingSigning => Brushes.DarkGreen,
+ SmartCoinStatus.SpentAccordingToBackend => Brushes.IndianRed,
+ SmartCoinStatus.MixingWaitingForConfirmation => Brushes.LightYellow,
+ _ => throw new NotSupportedException() // Or rather not implemented?
+ };
}
else
{

MODIFY
WalletWasabi.Gui/Converters/CoinStatusStringConverter.cs
WalletWasabi.Gui/Converters/CoinStatusStringConverter.cs
@@ -16,20 +16,20 @@ namespace WalletWasabi.Gui.Converters
{
if (value is SmartCoinStatus status)
{
- switch (status)
+ return status switch
{
- case SmartCoinStatus.Confirmed: return "";
- case SmartCoinStatus.Unconfirmed: return "";
- case SmartCoinStatus.MixingOnWaitingList: return " queued ";
- case SmartCoinStatus.MixingBanned: return " banned ";
- case SmartCoinStatus.MixingInputRegistration: return " registered ";
- case SmartCoinStatus.MixingConnectionConfirmation: return " connection confirmed ";
- case SmartCoinStatus.MixingOutputRegistration: return " output registered ";
- case SmartCoinStatus.MixingSigning: return " signed ";
- case SmartCoinStatus.SpentAccordingToBackend: return " spent ";
- case SmartCoinStatus.MixingWaitingForConfirmation: return " waiting for confirmation ";
- default: return "";
- }
+ SmartCoinStatus.Confirmed => "",
+ SmartCoinStatus.Unconfirmed => "",
+ SmartCoinStatus.MixingOnWaitingList => " queued ",
+ SmartCoinStatus.MixingBanned => " banned ",
+ SmartCoinStatus.MixingInputRegistration => " registered ",
+ SmartCoinStatus.MixingConnectionConfirmation => " connection confirmed ",
+ SmartCoinStatus.MixingOutputRegistration => " output registered ",
+ SmartCoinStatus.MixingSigning => " signed ",
+ SmartCoinStatus.SpentAccordingToBackend => " spent ",
+ SmartCoinStatus.MixingWaitingForConfirmation => " waiting for confirmation ",
+ _ => ""
+ };
}
else
{

MODIFY
WalletWasabi.Gui/Converters/PhaseStringConverter.cs
WalletWasabi.Gui/Converters/PhaseStringConverter.cs
@@ -14,14 +14,14 @@ namespace WalletWasabi.Gui.Converters
{
if (value is CcjRoundPhase phase)
{
- switch (phase)
- {
- case CcjRoundPhase.InputRegistration: return "Registration";
- case CcjRoundPhase.ConnectionConfirmation: return "Connection Confirmation";
- case CcjRoundPhase.OutputRegistration: return "Output Registration";
- case CcjRoundPhase.Signing: return "Signing";
- default: return "";
- }
+ return phase switch
+ {
+ CcjRoundPhase.InputRegistration => "Registration",
+ CcjRoundPhase.ConnectionConfirmation => "Connection Confirmation",
+ CcjRoundPhase.OutputRegistration => "Output Registration",
+ CcjRoundPhase.Signing => "Signing",
+ _ => ""
+ };
}
else
{

MODIFY
WalletWasabi.Gui/Converters/StatusBarStatusStringConverter.cs
WalletWasabi.Gui/Converters/StatusBarStatusStringConverter.cs
@@ -14,24 +14,24 @@ namespace WalletWasabi.Gui.Converters
{
if (value is StatusBarStatus status)
{
- switch (status)
+ return status switch
{
- case StatusBarStatus.Ready: return "Ready";
- case StatusBarStatus.CriticalUpdate: return "THE BACKEND WAS UPGRADED WITH BREAKING CHANGES - PLEASE UPDATE YOUR WASABI WALLET!";
- case StatusBarStatus.OptionalUpdate: return "A new version of Wasabi Wallet is available.";
- case StatusBarStatus.Connecting: return "Connecting...";
- case StatusBarStatus.Synchronizing: return "Synchronizing...";
- case StatusBarStatus.Loading: return "Loading...";
- case StatusBarStatus.SettingUpHardwareWallet: return "Setting up hardware wallet...";
- case StatusBarStatus.ConnectingToHardwareWallet: return "Connecting to hardware wallet...";
- case StatusBarStatus.AcquiringXpubFromHardwareWallet: return "Acquiring xpub from hardware wallet...";
- case StatusBarStatus.AcquiringSignatureFromHardwareWallet: return "Acquiring signature from hardware wallet...";
- case StatusBarStatus.BuildingTransaction: return "Building transaction...";
- case StatusBarStatus.SigningTransaction: return "Signing transaction...";
- case StatusBarStatus.BroadcastingTransaction: return "Broadcasting transaction...";
- case StatusBarStatus.DequeuingSelectedCoins: return "Dequeuing selected coins...";
- default: return status.ToString();
- }
+ StatusBarStatus.Ready => "Ready",
+ StatusBarStatus.CriticalUpdate => "THE BACKEND WAS UPGRADED WITH BREAKING CHANGES - PLEASE UPDATE YOUR WASABI WALLET!",
+ StatusBarStatus.OptionalUpdate => "A new version of Wasabi Wallet is available.",
+ StatusBarStatus.Connecting => "Connecting...",
+ StatusBarStatus.Synchronizing => "Synchronizing...",
+ StatusBarStatus.Loading => "Loading...",
+ StatusBarStatus.SettingUpHardwareWallet => "Setting up hardware wallet...",
+ StatusBarStatus.ConnectingToHardwareWallet => "Connecting to hardware wallet...",
+ StatusBarStatus.AcquiringXpubFromHardwareWallet => "Acquiring xpub from hardware wallet...",
+ StatusBarStatus.AcquiringSignatureFromHardwareWallet => "Acquiring signature from hardware wallet...",
+ StatusBarStatus.BuildingTransaction => "Building transaction...",
+ StatusBarStatus.SigningTransaction => "Signing transaction...",
+ StatusBarStatus.BroadcastingTransaction => "Broadcasting transaction...",
+ StatusBarStatus.DequeuingSelectedCoins => "Dequeuing selected coins...",
+ _ => status.ToString()
+ };
}
else
{

MODIFY
WalletWasabi.Tests/IntegrationTests/RegTests.cs
WalletWasabi.Tests/IntegrationTests/RegTests.cs
@@ -3069,41 +3069,17 @@ namespace WalletWasabi.Tests.IntegrationTests
// 1. Prepare and start services.
for (int i = 0; i < anonymitySet; i++)
{
- double damount;
- switch (i)
- {
- case 0:
- damount = 1;
- break;
-
- case 1:
- damount = 1.1;
- break;
-
- case 2:
- damount = 1.2;
- break;
-
- case 3:
- damount = 3.1;
- break;
-
- case 4:
- damount = 4.1;
- break;
-
- case 5:
- damount = 7.1;
- break;
-
- case 6:
- damount = 8.1;
- break;
-
- default:
- damount = 1;
- break;
- }
+ double damount = i switch
+ {
+ 0 => 1,
+ 1 => 1.1,
+ 2 => 1.2,
+ 3 => 3.1,
+ 4 => 4.1,
+ 5 => 7.1,
+ 6 => 8.1,
+ _ => 1
+ };
var amount = Money.Coins((decimal)damount);

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/EncodingRegion/FormatInformation.cs
WalletWasabi/Gma/QrCodeNet/Encoding/EncodingRegion/FormatInformation.cs
@@ -98,23 +98,14 @@ namespace Gma.QrCodeNet.Encoding.EncodingRegion
//M 00
//Q 11
//H 10
- switch (errorLevel)
+ return errorLevel switch
{
- case ErrorCorrectionLevel.H:
- return 0x02;
-
- case ErrorCorrectionLevel.L:
- return 0x01;
-
- case ErrorCorrectionLevel.M:
- return 0x00;
-
- case ErrorCorrectionLevel.Q:
- return 0x03;
-
- default:
- throw new ArgumentException($"Unsupported error correction level [{errorLevel}]", nameof(errorLevel));
- }
+ ErrorCorrectionLevel.H => 0x02,
+ ErrorCorrectionLevel.L => 0x01,
+ ErrorCorrectionLevel.M => 0x00,
+ ErrorCorrectionLevel.Q => 0x03,
+ _ => throw new ArgumentException($"Unsupported error correction level [{errorLevel}]", nameof(errorLevel))
+ };
}
}
}

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/Masking/PatternFactory.cs
WalletWasabi/Gma/QrCodeNet/Encoding/Masking/PatternFactory.cs
@@ -7,35 +7,18 @@ namespace Gma.QrCodeNet.Encoding.Masking
{
internal Pattern CreateByType(MaskPatternType maskPatternType)
{
- switch (maskPatternType)
+ return maskPatternType switch
{
- case MaskPatternType.Type0:
- return new Pattern0();
-
- case MaskPatternType.Type1:
- return new Pattern1();
-
- case MaskPatternType.Type2:
- return new Pattern2();
-
- case MaskPatternType.Type3:
- return new Pattern3();
-
- case MaskPatternType.Type4:
- return new Pattern4();
-
- case MaskPatternType.Type5:
- return new Pattern5();
-
- case MaskPatternType.Type6:
- return new Pattern6();
-
- case MaskPatternType.Type7:
- return new Pattern7();
-
- default:
- throw new NotSupportedException("This is impossible.");
- }
+ MaskPatternType.Type0 => new Pattern0(),
+ MaskPatternType.Type1 => new Pattern1(),
+ MaskPatternType.Type2 => new Pattern2(),
+ MaskPatternType.Type3 => new Pattern3(),
+ MaskPatternType.Type4 => new Pattern4(),
+ MaskPatternType.Type5 => new Pattern5(),
+ MaskPatternType.Type6 => new Pattern6(),
+ MaskPatternType.Type7 => new Pattern7(),
+ _ => throw new NotSupportedException("This is impossible.")
+ };
}
internal IEnumerable<Pattern> AllPatterns()

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/Masking/Scoring/PenaltyFactory.cs
WalletWasabi/Gma/QrCodeNet/Encoding/Masking/Scoring/PenaltyFactory.cs
@@ -10,23 +10,14 @@ namespace Gma.QrCodeNet.Encoding.Masking.Scoring
{
internal Penalty CreateByRule(PenaltyRules penaltyRule)
{
- switch (penaltyRule)
+ return penaltyRule switch
{
- case PenaltyRules.Rule01:
- return new Penalty1();
-
- case PenaltyRules.Rule02:
- return new Penalty2();
-
- case PenaltyRules.Rule03:
- return new Penalty3();
-
- case PenaltyRules.Rule04:
- return new Penalty4();
-
- default:
- throw new ArgumentException($"Unsupport penalty rule: {penaltyRule}", nameof(penaltyRule));
- }
+ PenaltyRules.Rule01 => new Penalty1(),
+ PenaltyRules.Rule02 => new Penalty2(),
+ PenaltyRules.Rule03 => new Penalty3(),
+ PenaltyRules.Rule04 => new Penalty4(),
+ _ => throw new ArgumentException($"Unsupport penalty rule: {penaltyRule}", nameof(penaltyRule))
+ };
}
internal IEnumerable<Penalty> AllRules()

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/Versions/QRCodeVersion.cs
WalletWasabi/Gma/QrCodeNet/Encoding/Versions/QRCodeVersion.cs
@@ -23,23 +23,14 @@ namespace Gma.QrCodeNet.Encoding.Versions
internal ErrorCorrectionBlocks GetECBlocksByLevel(ErrorCorrectionLevel eCLevel)
{
- switch (eCLevel)
+ return eCLevel switch
{
- case ErrorCorrectionLevel.L:
- return ECBlocks[0];
-
- case ErrorCorrectionLevel.M:
- return ECBlocks[1];
-
- case ErrorCorrectionLevel.Q:
- return ECBlocks[2];
-
- case ErrorCorrectionLevel.H:
- return ECBlocks[3];
-
- default:
- throw new ArgumentOutOfRangeException($"Invalid {nameof(ErrorCorrectionLevel)}.");
- }
+ ErrorCorrectionLevel.L => ECBlocks[0],
+ ErrorCorrectionLevel.M => ECBlocks[1],
+ ErrorCorrectionLevel.Q => ECBlocks[2],
+ ErrorCorrectionLevel.H => ECBlocks[3],
+ _ => throw new ArgumentOutOfRangeException($"Invalid {nameof(ErrorCorrectionLevel)}.")
+ };
}
}
}

Add rule to prefer switch expression