Skip to content

Commit 68d66d1

Browse files
committed
Fix IDE0078: Use pattern matching
1 parent d7c06e3 commit 68d66d1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ public virtual void SetValue(object resource, object? newValue)
115115

116116
protected void AssertIsIdentifiable(object? resource)
117117
{
118-
if (resource != null && resource is not IIdentifiable)
118+
if (resource is not null and not IIdentifiable)
119119
{
120+
#pragma warning disable CA1062 // Validate arguments of public methods
120121
throw new InvalidOperationException($"Resource of type '{resource.GetType()}' does not implement {nameof(IIdentifiable)}.");
122+
#pragma warning restore CA1062 // Validate arguments of public methods
121123
}
122124
}
123125

test/JsonApiDotNetCoreTests/IntegrationTests/NamingConventions/JsonKebabCaseNamingPolicy.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public override string ConvertName(string name)
3636

3737
if (position + 1 != spanName.Length)
3838
{
39-
isNextLower = spanName[position + 1] > 96 && spanName[position + 1] < 123;
40-
isNextUpper = spanName[position + 1] > 64 && spanName[position + 1] < 91;
41-
isNextSpace = spanName[position + 1] == 32;
39+
isNextLower = spanName[position + 1] is >= 'a' and <= 'z';
40+
isNextUpper = spanName[position + 1] is >= 'A' and <= 'Z';
41+
isNextSpace = spanName[position + 1] == ' ';
4242
}
4343

4444
if (isCurrentSpace && (isPreviousSpace || isPreviousSeparator || isNextUpper || isNextSpace))
@@ -47,9 +47,9 @@ public override string ConvertName(string name)
4747
}
4848
else
4949
{
50-
bool isCurrentUpper = spanName[position] > 64 && spanName[position] < 91;
51-
bool isPreviousLower = spanName[position - 1] > 96 && spanName[position - 1] < 123;
52-
bool isPreviousNumber = spanName[position - 1] > 47 && spanName[position - 1] < 58;
50+
bool isCurrentUpper = spanName[position] is >= 'A' and <= 'Z';
51+
bool isPreviousLower = spanName[position - 1] is >= 'a' and <= 'z';
52+
bool isPreviousNumber = spanName[position - 1] is >= '0' and <= '9';
5353

5454
if (isCurrentUpper && (isPreviousLower || isPreviousNumber || isNextLower || isNextSpace))
5555
{

0 commit comments

Comments
 (0)