Skip to content

Commit 1eb6e15

Browse files
committed
Apply new Resharper suggestion: use explicit default value
1 parent c919e5e commit 1eb6e15

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/Car.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public sealed class Car : Identifiable<string?>
1212
[NotMapped]
1313
public override string? Id
1414
{
15-
get => RegionId == default && LicensePlate == default ? null : $"{RegionId}:{LicensePlate}";
15+
get => RegionId == 0 && LicensePlate == null ? null : $"{RegionId}:{LicensePlate}";
1616
set
1717
{
1818
if (value == null)
1919
{
20-
RegionId = default;
21-
LicensePlate = default;
20+
RegionId = 0;
21+
LicensePlate = null;
2222
return;
2323
}
2424

test/JsonApiDotNetCoreTests/IntegrationTests/IdObfuscation/ObfuscatedIdentifiable.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ public abstract class ObfuscatedIdentifiable : Identifiable<int>
88

99
protected override string? GetStringId(int value)
1010
{
11-
return value == default ? null : Codec.Encode(value);
11+
return value == 0 ? null : Codec.Encode(value);
1212
}
1313

1414
protected override int GetTypedId(string? value)
1515
{
16-
return value == null ? default : Codec.Decode(value);
16+
return value == null ? 0 : Codec.Decode(value);
1717
}
1818
}

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SerializerIgnoreConditionTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task Applies_configuration_for_ignore_condition(JsonIgnoreCondition
3232

3333
Calendar calendar = _fakers.Calendar.GenerateOne();
3434
calendar.TimeZone = null;
35-
calendar.DefaultAppointmentDurationInMinutes = default;
35+
calendar.DefaultAppointmentDurationInMinutes = 0;
3636
calendar.ShowWeekNumbers = true;
3737
calendar.MostRecentAppointment = _fakers.Appointment.GenerateOne();
3838
calendar.MostRecentAppointment.Description = null;

test/JsonApiDotNetCoreTests/UnitTests/Serialization/InputConversionTests.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,26 @@ public void Converts_various_data_types_with_defaults()
153153
WriteOperation = WriteOperationKind.CreateResource
154154
});
155155

156-
const bool booleanValue = default;
157-
const bool nullableBooleanValue = default;
158-
const char charValue = default;
159-
const char nullableCharValue = default;
160-
const ulong unsignedLongValue = default;
161-
const ulong nullableUnsignedLongValue = default;
162-
const decimal decimalValue = default;
163-
const decimal nullableDecimalValue = default;
164-
const float floatValue = default;
165-
const float nullableFloatValue = default;
166-
const string stringValue = default!;
167-
const string? nullableStringValue = default;
168-
Guid guidValue = default;
169-
Guid nullableGuidValue = default;
156+
const bool booleanValue = false;
157+
const bool nullableBooleanValue = false;
158+
const char charValue = '\0';
159+
const char nullableCharValue = '\0';
160+
const ulong unsignedLongValue = 0;
161+
const ulong nullableUnsignedLongValue = 0;
162+
const decimal decimalValue = 0;
163+
const decimal nullableDecimalValue = 0;
164+
const float floatValue = 0;
165+
const float nullableFloatValue = 0;
166+
const string stringValue = null!;
167+
const string? nullableStringValue = null;
168+
var guidValue = Guid.Empty;
169+
var nullableGuidValue = Guid.Empty;
170170
DateTime dateTimeValue = default;
171171
DateTime nullableDateTimeValue = default;
172172
DateTimeOffset dateTimeOffsetValue = default;
173173
DateTimeOffset nullableDateTimeOffsetValue = default;
174-
TimeSpan timeSpanValue = default;
175-
TimeSpan nullableTimeSpanValue = default;
174+
TimeSpan timeSpanValue = TimeSpan.Zero;
175+
TimeSpan nullableTimeSpanValue = TimeSpan.Zero;
176176
const DayOfWeek enumValue = default;
177177
const DayOfWeek nullableEnumValue = default;
178178

test/JsonApiDotNetCoreTests/UnitTests/TypeConversion/RuntimeTypeConverterTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,29 @@ public void Returns_same_instance_for_interface()
109109
}
110110

111111
[Theory]
112-
[InlineData(typeof(bool), default(bool))]
112+
[InlineData(typeof(bool), false)]
113113
[InlineData(typeof(bool?), null)]
114-
[InlineData(typeof(byte), default(byte))]
114+
[InlineData(typeof(byte), 0)]
115115
[InlineData(typeof(byte?), null)]
116-
[InlineData(typeof(sbyte), default(sbyte))]
116+
[InlineData(typeof(sbyte), 0)]
117117
[InlineData(typeof(sbyte?), null)]
118-
[InlineData(typeof(char), default(char))]
118+
[InlineData(typeof(char), '\0')]
119119
[InlineData(typeof(char?), null)]
120-
[InlineData(typeof(short), default(short))]
120+
[InlineData(typeof(short), 0)]
121121
[InlineData(typeof(short?), null)]
122-
[InlineData(typeof(ushort), default(ushort))]
122+
[InlineData(typeof(ushort), 0)]
123123
[InlineData(typeof(ushort?), null)]
124-
[InlineData(typeof(int), default(int))]
124+
[InlineData(typeof(int), 0)]
125125
[InlineData(typeof(int?), null)]
126-
[InlineData(typeof(uint), default(uint))]
126+
[InlineData(typeof(uint), 0)]
127127
[InlineData(typeof(uint?), null)]
128-
[InlineData(typeof(long), default(long))]
128+
[InlineData(typeof(long), 0)]
129129
[InlineData(typeof(long?), null)]
130-
[InlineData(typeof(ulong), default(ulong))]
130+
[InlineData(typeof(ulong), 0)]
131131
[InlineData(typeof(ulong?), null)]
132-
[InlineData(typeof(float), default(float))]
132+
[InlineData(typeof(float), 0)]
133133
[InlineData(typeof(float?), null)]
134-
[InlineData(typeof(double), default(double))]
134+
[InlineData(typeof(double), 0)]
135135
[InlineData(typeof(double?), null)]
136136
[InlineData(typeof(decimal), 0)]
137137
[InlineData(typeof(decimal?), null)]

test/UnitTests/Models/IdentifiableTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void GetStringId_Returns_Null_If_Object_Is_Default()
3333
{
3434
var resource = new IntId();
3535

36-
string? stringId = resource.ExposedGetStringId(default);
36+
string? stringId = resource.ExposedGetStringId(0);
3737

3838
stringId.Should().BeNull();
3939
}

0 commit comments

Comments
 (0)