1
- using System . Text . Json ;
2
1
using JetBrains . Annotations ;
3
2
using JsonApiDotNetCore . Middleware ;
4
3
using JsonApiDotNetCore . Resources . Annotations ;
@@ -13,9 +12,9 @@ public sealed class ResourceChangeTracker<TResource> : IResourceChangeTracker<TR
13
12
private readonly IJsonApiRequest _request ;
14
13
private readonly ITargetedFields _targetedFields ;
15
14
16
- private IDictionary < string , string > ? _initiallyStoredAttributeValues ;
17
- private IDictionary < string , string > ? _requestAttributeValues ;
18
- private IDictionary < string , string > ? _finallyStoredAttributeValues ;
15
+ private IDictionary < string , object ? > ? _initiallyStoredAttributeValues ;
16
+ private IDictionary < string , object ? > ? _requestAttributeValues ;
17
+ private IDictionary < string , object ? > ? _finallyStoredAttributeValues ;
19
18
20
19
public ResourceChangeTracker ( IJsonApiRequest request , ITargetedFields targetedFields )
21
20
{
@@ -50,15 +49,14 @@ public void SetFinallyStoredAttributeValues(TResource resource)
50
49
_finallyStoredAttributeValues = CreateAttributeDictionary ( resource , _request . PrimaryResourceType ! . Attributes ) ;
51
50
}
52
51
53
- private IDictionary < string , string > CreateAttributeDictionary ( TResource resource , IEnumerable < AttrAttribute > attributes )
52
+ private IDictionary < string , object ? > CreateAttributeDictionary ( TResource resource , IEnumerable < AttrAttribute > attributes )
54
53
{
55
- var result = new Dictionary < string , string > ( ) ;
54
+ var result = new Dictionary < string , object ? > ( ) ;
56
55
57
56
foreach ( AttrAttribute attribute in attributes )
58
57
{
59
58
object ? value = attribute . GetValue ( resource ) ;
60
- string json = JsonSerializer . Serialize ( value ) ;
61
- result . Add ( attribute . PublicName , json ) ;
59
+ result . Add ( attribute . PublicName , value ) ;
62
60
}
63
61
64
62
return result ;
@@ -71,21 +69,21 @@ public bool HasImplicitChanges()
71
69
{
72
70
foreach ( string key in _initiallyStoredAttributeValues . Keys )
73
71
{
74
- if ( _requestAttributeValues . TryGetValue ( key , out string ? requestValue ) )
72
+ if ( _requestAttributeValues . TryGetValue ( key , out object ? requestValue ) )
75
73
{
76
- string actualValue = _finallyStoredAttributeValues [ key ] ;
74
+ object ? actualValue = _finallyStoredAttributeValues [ key ] ;
77
75
78
- if ( requestValue != actualValue )
76
+ if ( ! Equals ( requestValue , actualValue ) )
79
77
{
80
78
return true ;
81
79
}
82
80
}
83
81
else
84
82
{
85
- string initiallyStoredValue = _initiallyStoredAttributeValues [ key ] ;
86
- string finallyStoredValue = _finallyStoredAttributeValues [ key ] ;
83
+ object ? initiallyStoredValue = _initiallyStoredAttributeValues [ key ] ;
84
+ object ? finallyStoredValue = _finallyStoredAttributeValues [ key ] ;
87
85
88
- if ( initiallyStoredValue != finallyStoredValue )
86
+ if ( ! Equals ( initiallyStoredValue , finallyStoredValue ) )
89
87
{
90
88
return true ;
91
89
}
0 commit comments