Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class DefaultConstraint : ConstraintBase
public override bool IsSatisfiedBy(object? value) =>
value?.GetType() switch
{
{ IsValueType: true } valueType => TypeExtensions.GetDefault(valueType)?.Equals(value) ?? false,
{ IsValueType: true } valueType => Equals(TypeExtensions.GetDefault(valueType), value),
_ => false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class NotDefaultConstraint : ConstraintBase
public override bool IsSatisfiedBy(object? value) =>
value?.GetType() switch
{
{ IsValueType: true } valueType => !TypeExtensions.GetDefault(valueType)?.Equals(value) ?? false,
{ IsValueType: true } valueType => !Equals(TypeExtensions.GetDefault(valueType), value),
_ => true,
};

Expand Down
16 changes: 2 additions & 14 deletions src/NetEvolve.FluentValue/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

internal static class TypeExtensions
{
internal static object? GetDefault(this Type value)
{
if (!value.IsValueType)
{
return null;
}

var underlying = Nullable.GetUnderlyingType(value);
if (underlying is not null)
{
return null;
}
return Activator.CreateInstance(value)!;
}
// Nullable<T> yields null from Activator.CreateInstance, so no explicit handling is needed.
internal static object? GetDefault(this Type value) => value.IsValueType ? Activator.CreateInstance(value) : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TypeExtensionsTests
{
[Test]
[MethodDataSource(nameof(GetDefaultData))]
public async Task IsNullableType_ShouldReturnTrue_WhenTypeIsNullable(object? expected, Type type)
public async Task GetDefault_ShouldReturnExpected(object? expected, Type type)
{
// Arrange & Act
var result = TypeExtensions.GetDefault(type);
Expand Down
Loading