Warning if not using 'is not null'

This commit is contained in:
nicolas.dorier 2022-01-14 17:48:15 +09:00
parent 5cbc2e96e7
commit c6a7e90c1a
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
9 changed files with 13 additions and 11 deletions

View file

@ -121,8 +121,10 @@ csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false csharp_space_between_square_brackets = false
csharp_style_prefer_null_check_over_type_check = true:warning
# C++ Files # C++ Files
[*.{cpp,h,in}] [*.{cpp,h,in}]
curly_bracket_next_line = true curly_bracket_next_line = true
indent_brace_style = Allman indent_brace_style = Allman

View file

@ -19,7 +19,7 @@ namespace BTCPayServer.Client.JsonConverters
public override void WriteJson(JsonWriter writer, [AllowNull] NodeInfo value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, [AllowNull] NodeInfo value, JsonSerializer serializer)
{ {
if (value is NodeInfo) if (value is not null)
writer.WriteValue(value.ToString()); writer.WriteValue(value.ToString());
} }
} }

View file

@ -95,7 +95,7 @@ namespace BTCPayServer.Services.Rates
{ {
LastRequested = LastRequested LastRequested = LastRequested
}; };
if (_Latest is LatestFetch fetch && fetch.Latest is PairRate[]) if (_Latest is LatestFetch fetch && fetch.Latest is not null)
{ {
state.LastUpdated = fetch.Updated; state.LastUpdated = fetch.Updated;
state.Rates = fetch.Latest state.Rates = fetch.Latest

View file

@ -479,7 +479,7 @@ namespace BTCPayServer.Tests
currencyEl.Clear(); currencyEl.Clear();
currencyEl.SendKeys(currency); currencyEl.SendKeys(currency);
Driver.FindElement(By.Id("BuyerEmail")).SendKeys(refundEmail); Driver.FindElement(By.Id("BuyerEmail")).SendKeys(refundEmail);
if (defaultPaymentMethod is string) if (defaultPaymentMethod is not null)
new SelectElement(Driver.FindElement(By.Name("DefaultPaymentMethod"))).SelectByValue(defaultPaymentMethod); new SelectElement(Driver.FindElement(By.Name("DefaultPaymentMethod"))).SelectByValue(defaultPaymentMethod);
if (requiresRefundEmail is bool) if (requiresRefundEmail is bool)
new SelectElement(Driver.FindElement(By.Name("RequiresRefundEmail"))).SelectByValue(requiresRefundEmail == true ? "1" : "2"); new SelectElement(Driver.FindElement(By.Name("RequiresRefundEmail"))).SelectByValue(requiresRefundEmail == true ? "1" : "2");

View file

@ -500,21 +500,21 @@ namespace BTCPayServer.Controllers
var enabledPaymentIds = store.GetEnabledPaymentIds(_NetworkProvider); var enabledPaymentIds = store.GetEnabledPaymentIds(_NetworkProvider);
PaymentMethodId? invoicePaymentId = invoice.GetDefaultPaymentMethod(); PaymentMethodId? invoicePaymentId = invoice.GetDefaultPaymentMethod();
PaymentMethodId? storePaymentId = store.GetDefaultPaymentId(); PaymentMethodId? storePaymentId = store.GetDefaultPaymentId();
if (invoicePaymentId is PaymentMethodId) if (invoicePaymentId is not null)
{ {
if (enabledPaymentIds.Contains(invoicePaymentId)) if (enabledPaymentIds.Contains(invoicePaymentId))
paymentMethodId = invoicePaymentId; paymentMethodId = invoicePaymentId;
} }
if (paymentMethodId is null && storePaymentId is PaymentMethodId) if (paymentMethodId is null && storePaymentId is not null)
{ {
if (enabledPaymentIds.Contains(storePaymentId)) if (enabledPaymentIds.Contains(storePaymentId))
paymentMethodId = storePaymentId; paymentMethodId = storePaymentId;
} }
if (paymentMethodId is null && invoicePaymentId is PaymentMethodId) if (paymentMethodId is null && invoicePaymentId is not null)
{ {
paymentMethodId = invoicePaymentId.FindNearest(enabledPaymentIds); paymentMethodId = invoicePaymentId.FindNearest(enabledPaymentIds);
} }
if (paymentMethodId is null && storePaymentId is PaymentMethodId) if (paymentMethodId is null && storePaymentId is not null)
{ {
paymentMethodId = storePaymentId.FindNearest(enabledPaymentIds); paymentMethodId = storePaymentId.FindNearest(enabledPaymentIds);
} }

View file

@ -419,7 +419,7 @@ namespace BTCPayServer.Controllers
{ {
var enabled = storeData.GetEnabledPaymentIds(_NetworkProvider); var enabled = storeData.GetEnabledPaymentIds(_NetworkProvider);
var defaultPaymentId = storeData.GetDefaultPaymentId(); var defaultPaymentId = storeData.GetDefaultPaymentId();
var defaultChoice = defaultPaymentId is PaymentMethodId ? defaultPaymentId.FindNearest(enabled) : null; var defaultChoice = defaultPaymentId is not null ? defaultPaymentId.FindNearest(enabled) : null;
if (defaultChoice is null) if (defaultChoice is null)
{ {
defaultChoice = enabled.FirstOrDefault(e => e.CryptoCode == "BTC" && e.PaymentType == PaymentTypes.BTCLike) ?? defaultChoice = enabled.FirstOrDefault(e => e.CryptoCode == "BTC" && e.PaymentType == PaymentTypes.BTCLike) ??

View file

@ -40,7 +40,7 @@ namespace BTCPayServer
// but we want searchTerm to be null only if the user is browsing the page via some link // but we want searchTerm to be null only if the user is browsing the page via some link
// NOT if the user entered some empty search // NOT if the user entered some empty search
var searchTerm = model.SearchTerm; var searchTerm = model.SearchTerm;
searchTerm = searchTerm is string ? searchTerm : searchTerm = searchTerm is not null ? searchTerm :
ctrl.Request.Query.ContainsKey(nameof(searchTerm)) ? string.Empty : ctrl.Request.Query.ContainsKey(nameof(searchTerm)) ? string.Empty :
null; null;
if (searchTerm is null) if (searchTerm is null)

View file

@ -254,7 +254,7 @@ namespace BTCPayServer.HostedServices
var result = await SendAndSaveDelivery(ctx, cancellationToken); var result = await SendAndSaveDelivery(ctx, cancellationToken);
if (ctx.WebhookBlob.AutomaticRedelivery && if (ctx.WebhookBlob.AutomaticRedelivery &&
!result.Success && !result.Success &&
result.DeliveryId is string) result.DeliveryId is not null)
{ {
var originalDeliveryId = result.DeliveryId; var originalDeliveryId = result.DeliveryId;
foreach (var wait in new[] foreach (var wait in new[]

View file

@ -58,7 +58,7 @@ namespace BTCPayServer.Security.Greenfield
{ {
if (Permission.TryParse(claim.Value, out var claimPermission)) if (Permission.TryParse(claim.Value, out var claimPermission))
{ {
if (requireUnscoped && claimPermission.Scope is string) if (requireUnscoped && claimPermission.Scope is not null)
continue; continue;
if (claimPermission.Contains(permission)) if (claimPermission.Contains(permission))
{ {