Skip to content

Commit

Permalink
Apply new Resharper suggestion: use explicit default value
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Dec 24, 2024
1 parent 9384d10 commit d3cd23c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public sealed class Car : Identifiable<string?>
[NotMapped]
public override string? Id
{
get => RegionId == default && LicensePlate == default ? null : $"{RegionId}:{LicensePlate}";
get => RegionId == 0 && LicensePlate == null ? null : $"{RegionId}:{LicensePlate}";
set
{
if (value == null)
{
RegionId = default;
LicensePlate = default;
RegionId = 0;
LicensePlate = null;
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public abstract class ObfuscatedIdentifiable : Identifiable<int>

protected override string? GetStringId(int value)
{
return value == default ? null : Codec.Encode(value);
return value == 0 ? null : Codec.Encode(value);
}

protected override int GetTypedId(string? value)
{
return value == null ? default : Codec.Decode(value);
return value == null ? 0 : Codec.Decode(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task Applies_configuration_for_ignore_condition(JsonIgnoreCondition

Calendar calendar = _fakers.Calendar.GenerateOne();
calendar.TimeZone = null;
calendar.DefaultAppointmentDurationInMinutes = default;
calendar.DefaultAppointmentDurationInMinutes = 0;
calendar.ShowWeekNumbers = true;
calendar.MostRecentAppointment = _fakers.Appointment.GenerateOne();
calendar.MostRecentAppointment.Description = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,26 @@ public void Converts_various_data_types_with_defaults()
WriteOperation = WriteOperationKind.CreateResource
});

const bool booleanValue = default;
const bool nullableBooleanValue = default;
const char charValue = default;
const char nullableCharValue = default;
const ulong unsignedLongValue = default;
const ulong nullableUnsignedLongValue = default;
const decimal decimalValue = default;
const decimal nullableDecimalValue = default;
const float floatValue = default;
const float nullableFloatValue = default;
const string stringValue = default!;
const string? nullableStringValue = default;
Guid guidValue = default;
Guid nullableGuidValue = default;
const bool booleanValue = false;
const bool nullableBooleanValue = false;
const char charValue = '\0';
const char nullableCharValue = '\0';
const ulong unsignedLongValue = 0;
const ulong nullableUnsignedLongValue = 0;
const decimal decimalValue = 0;
const decimal nullableDecimalValue = 0;
const float floatValue = 0;
const float nullableFloatValue = 0;
const string stringValue = null!;
const string? nullableStringValue = null;
Guid guidValue = Guid.Empty;
Guid nullableGuidValue = Guid.Empty;
DateTime dateTimeValue = default;
DateTime nullableDateTimeValue = default;
DateTimeOffset dateTimeOffsetValue = default;
DateTimeOffset nullableDateTimeOffsetValue = default;
TimeSpan timeSpanValue = default;
TimeSpan nullableTimeSpanValue = default;
TimeSpan timeSpanValue = TimeSpan.Zero;
TimeSpan nullableTimeSpanValue = TimeSpan.Zero;
const DayOfWeek enumValue = default;
const DayOfWeek nullableEnumValue = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,29 @@ public void Returns_same_instance_for_interface()
}

[Theory]
[InlineData(typeof(bool), default(bool))]
[InlineData(typeof(bool), false)]
[InlineData(typeof(bool?), null)]
[InlineData(typeof(byte), default(byte))]
[InlineData(typeof(byte), 0)]
[InlineData(typeof(byte?), null)]
[InlineData(typeof(sbyte), default(sbyte))]
[InlineData(typeof(sbyte), 0)]
[InlineData(typeof(sbyte?), null)]
[InlineData(typeof(char), default(char))]
[InlineData(typeof(char), '\0')]
[InlineData(typeof(char?), null)]
[InlineData(typeof(short), default(short))]
[InlineData(typeof(short), 0)]
[InlineData(typeof(short?), null)]
[InlineData(typeof(ushort), default(ushort))]
[InlineData(typeof(ushort), 0)]
[InlineData(typeof(ushort?), null)]
[InlineData(typeof(int), default(int))]
[InlineData(typeof(int), 0)]
[InlineData(typeof(int?), null)]
[InlineData(typeof(uint), default(uint))]
[InlineData(typeof(uint), 0)]
[InlineData(typeof(uint?), null)]
[InlineData(typeof(long), default(long))]
[InlineData(typeof(long), 0)]
[InlineData(typeof(long?), null)]
[InlineData(typeof(ulong), default(ulong))]
[InlineData(typeof(ulong), 0)]
[InlineData(typeof(ulong?), null)]
[InlineData(typeof(float), default(float))]
[InlineData(typeof(float), 0)]
[InlineData(typeof(float?), null)]
[InlineData(typeof(double), default(double))]
[InlineData(typeof(double), 0)]
[InlineData(typeof(double?), null)]
[InlineData(typeof(decimal), 0)]
[InlineData(typeof(decimal?), null)]
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTests/Models/IdentifiableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void GetStringId_Returns_Null_If_Object_Is_Default()
{
var resource = new IntId();

string? stringId = resource.ExposedGetStringId(default);
string? stringId = resource.ExposedGetStringId(0);

stringId.Should().BeNull();
}
Expand Down

0 comments on commit d3cd23c

Please sign in to comment.