Skip to content

Commit 2885899

Browse files
Refactor default value handling logic
Updated `GetDefault` methods in `AutoObservableProvider.cs` and `AutoTaskProvider.cs` to use the `DefaultForType` class for determining default values, improving code modularity and reusability.
1 parent 1c12153 commit 2885899

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/NSubstitute/Routing/AutoValues/AutoObservableProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public bool CanProvideValueFor(Type type) =>
2121

2222
private static object? GetDefault(Type type)
2323
{
24-
return type.GetTypeInfo().IsValueType ? Activator.CreateInstance(type) : null;
24+
var defaultForType = new DefaultForType();
25+
return defaultForType.GetDefaultFor(type);
2526
}
2627
}

src/NSubstitute/Routing/AutoValues/AutoTaskProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NSubstitute.Core;
12
using System.Reflection;
23

34
namespace NSubstitute.Routing.AutoValues;
@@ -32,6 +33,7 @@ public object GetValue(Type type)
3233

3334
private static object? GetDefault(Type type)
3435
{
35-
return type.GetTypeInfo().IsValueType ? Activator.CreateInstance(type) : null;
36+
var defaultForType = new DefaultForType();
37+
return defaultForType.GetDefaultFor(type);
3638
}
3739
}

0 commit comments

Comments
 (0)