File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
src/Primitively/EmbeddedResources/Integer
test/Primitively.IntegrationTests Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 6
6
public const global ::PRIMITIVE_VALUE_TYPE Minimum = PRIMITIVE_MINIMUM ;
7
7
public const global ::PRIMITIVE_VALUE_TYPE Maximum = PRIMITIVE_MAXIMUM ;
8
8
9
+ public PRIMITIVE_TYPE ( )
10
+ {
11
+ HasValue = IsMatch ( _value ) ;
12
+ _value = default ;
13
+ }
14
+
9
15
public PRIMITIVE_TYPE ( global ::PRIMITIVE_VALUE_TYPE value )
10
16
{
11
- if ( value >= Minimum && value <= Maximum )
12
- {
13
- _value = value ;
14
- HasValue = true ;
15
- }
17
+ HasValue = IsMatch ( value ) ;
18
+ _value = HasValue ? value : default ;
16
19
}
17
20
18
21
private PRIMITIVE_TYPE ( string value )
19
22
{
20
- if ( global ::PRIMITIVE_VALUE_TYPE . TryParse ( value , out var result ) && result >= Minimum && result <= Maximum )
21
- {
22
- _value = result ;
23
- HasValue = true ;
24
- }
23
+ HasValue = global ::PRIMITIVE_VALUE_TYPE . TryParse ( value , out var result ) && IsMatch ( result ) ;
24
+ _value = HasValue ? result : default ;
25
25
}
26
26
27
27
object global ::Primitively . IPrimitive . Value => _value ;
@@ -49,3 +49,5 @@ private PRIMITIVE_TYPE(string value)
49
49
50
50
public static PRIMITIVE_TYPE Parse ( string value ) => new ( value ) ;
51
51
public static bool TryParse ( string value , out PRIMITIVE_TYPE result ) => ( result = new ( value ) ) . HasValue ;
52
+
53
+ private static bool IsMatch ( global ::PRIMITIVE_VALUE_TYPE value ) => value >= Minimum && value <= Maximum ;
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public void JsonConverter_CanReadDefault()
48
48
49
49
var result = converter . Read ( ref reader , typeof ( TPrimitive ) , new JsonSerializerOptions ( ) ) ;
50
50
result . Should ( ) . BeAssignableTo ( typeof ( TPrimitive ) ) ;
51
- result . Should ( ) . BeEquivalentTo ( default ( TPrimitive ) ) ;
51
+ result . Should ( ) . BeEquivalentTo ( new TPrimitive ( ) ) ;
52
52
}
53
53
54
54
[ Fact ]
@@ -67,7 +67,7 @@ public void JsonConverter_CanReadNull()
67
67
68
68
var result = converter . Read ( ref reader , typeof ( TPrimitive ) , new JsonSerializerOptions ( ) ) ;
69
69
result . Should ( ) . BeAssignableTo ( typeof ( TPrimitive ) ) ;
70
- result . Should ( ) . BeEquivalentTo ( default ( TPrimitive ) ) ;
70
+ result . Should ( ) . BeEquivalentTo ( new TPrimitive ( ) ) ;
71
71
}
72
72
73
73
#if NET6_0_OR_GREATER
You can’t perform that action at this time.
0 commit comments