@@ -24,15 +24,28 @@ public static Type GetTypeFromModelRelationshipName(Type modelType, string relat
2424
2525 public static object SetValuesOnModelInstance ( object model , Dictionary < string , object > jsonApiAttributes , Dictionary < string , object > jsonApiRelationships )
2626 {
27- var modelProperties = model . GetType ( ) . GetProperties ( ) . ToList ( ) ;
27+ var patches = GetEntityPatch ( model . GetType ( ) , jsonApiAttributes , jsonApiRelationships ) ;
28+ foreach ( var patch in patches )
29+ {
30+ patch . Key . SetValue ( model , patch . Value ) ;
31+ }
32+
33+ return model ;
34+ }
35+
36+ public static Dictionary < PropertyInfo , object > GetEntityPatch ( Type modelType , Dictionary < string , object > jsonApiAttributes , Dictionary < string , object > jsonApiRelationships )
37+ {
38+ var patchDefinitions = new Dictionary < PropertyInfo , object > ( ) ;
39+
40+ var modelProperties = modelType . GetProperties ( ) . ToList ( ) ;
2841 foreach ( var attribute in jsonApiAttributes )
2942 {
3043 modelProperties . ForEach ( pI =>
3144 {
3245 if ( pI . Name . ToProperCase ( ) == attribute . Key . ToProperCase ( ) )
3346 {
3447 var convertedValue = Convert . ChangeType ( attribute . Value , pI . PropertyType ) ;
35- pI . SetValue ( model , convertedValue ) ;
48+ patchDefinitions . Add ( pI , convertedValue ) ;
3649 }
3750 } ) ;
3851 }
@@ -49,13 +62,13 @@ public static object SetValuesOnModelInstance(object model, Dictionary<string, o
4962 if ( pI . Name . ToProperCase ( ) == relationshipPropertyName . ToProperCase ( ) )
5063 {
5164 var convertedValue = Convert . ChangeType ( relationshipId , pI . PropertyType ) ;
52- pI . SetValue ( model , convertedValue ) ;
65+ patchDefinitions . Add ( pI , convertedValue ) ;
5366 }
5467 } ) ;
5568 }
5669 }
5770
58- return model ;
71+ return patchDefinitions ;
5972 }
6073 }
6174}
0 commit comments