22using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
5- using System . Text ;
6- using System . Threading . Tasks ;
75using JSONAPI . Documents ;
86using JSONAPI . Json ;
97
@@ -13,11 +11,34 @@ namespace JSONAPI.Core
1311 /// Populates property values on an ephemeral resource
1412 /// </summary>
1513 /// <typeparam name="T"></typeparam>
14+ [ Obsolete ]
1615 public class EphemeralRelatedResourceReader < T > : IEphemeralRelatedResourceReader < T >
16+ {
17+ private readonly IEphemeralRelatedResourceReader _ephemeralRelatedResourceReader ;
18+
19+ /// <summary>
20+ /// Creates a new EphemeralRelatedResourceReader
21+ /// </summary>
22+ /// <param name="ephemeralRelatedResourceReader"></param>
23+ public EphemeralRelatedResourceReader ( IEphemeralRelatedResourceReader ephemeralRelatedResourceReader )
24+ {
25+ _ephemeralRelatedResourceReader = ephemeralRelatedResourceReader ;
26+ }
27+
28+ public void SetProperty ( T ephemeralResource , string jsonKey , IRelationshipObject relationshipObject )
29+ {
30+ _ephemeralRelatedResourceReader . SetProperty ( ephemeralResource , jsonKey , relationshipObject ) ;
31+ }
32+ }
33+
34+ /// <summary>
35+ /// Populates property values on an ephemeral resource
36+ /// </summary>
37+ /// <typeparam name="T"></typeparam>
38+ public class EphemeralRelatedResourceReader : IEphemeralRelatedResourceReader
1739 {
1840 private readonly IResourceTypeRegistry _resourceTypeRegistry ;
1941 private readonly IEphemeralRelatedResourceCreator _ephemeralRelatedResourceCreator ;
20- private readonly Lazy < IResourceTypeRegistration > _resourceTypeRegistration ;
2142 private readonly MethodInfo _openSetToManyRelationshipValueMethod ;
2243
2344 /// <summary>
@@ -29,14 +50,14 @@ public EphemeralRelatedResourceReader(IResourceTypeRegistry resourceTypeRegistry
2950 {
3051 _resourceTypeRegistry = resourceTypeRegistry ;
3152 _ephemeralRelatedResourceCreator = ephemeralRelatedResourceCreator ;
32- _resourceTypeRegistration = new Lazy < IResourceTypeRegistration > ( ( ) => _resourceTypeRegistry . GetRegistrationForType ( typeof ( T ) ) ) ;
3353 _openSetToManyRelationshipValueMethod = GetType ( )
3454 . GetMethod ( "SetToManyRelationshipValue" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
3555 }
3656
37- public void SetProperty ( T ephemeralResource , string jsonKey , IRelationshipObject relationshipObject )
57+ public void SetProperty < T > ( T ephemeralResource , string jsonKey , IRelationshipObject relationshipObject )
3858 {
39- var relationship = _resourceTypeRegistration . Value . GetFieldByName ( jsonKey ) as ResourceTypeRelationship ;
59+ var resourceTypeRegistration = new Lazy < IResourceTypeRegistration > ( ( ) => _resourceTypeRegistry . GetRegistrationForType ( typeof ( T ) ) ) ;
60+ var relationship = resourceTypeRegistration . Value . GetFieldByName ( jsonKey ) as ResourceTypeRelationship ;
4061 if ( relationship == null ) return ;
4162
4263 if ( relationship . IsToMany )
@@ -45,7 +66,7 @@ public void SetProperty(T ephemeralResource, string jsonKey, IRelationshipObject
4566 SetPropertyForToOneRelationship ( ephemeralResource , relationship , relationshipObject . Linkage ) ;
4667 }
4768
48- protected virtual void SetPropertyForToOneRelationship ( T ephemeralResource , ResourceTypeRelationship relationship , IResourceLinkage linkage )
69+ protected virtual void SetPropertyForToOneRelationship < T > ( T ephemeralResource , ResourceTypeRelationship relationship , IResourceLinkage linkage )
4970 {
5071 if ( linkage == null )
5172 throw new DeserializationException ( "Missing linkage for to-one relationship" ,
@@ -70,7 +91,7 @@ protected virtual void SetPropertyForToOneRelationship(T ephemeralResource, Reso
7091 }
7192 }
7293
73- protected virtual void SetPropertyForToManyRelationship ( T ephemeralResource , ResourceTypeRelationship relationship ,
94+ protected virtual void SetPropertyForToManyRelationship < T > ( T ephemeralResource , ResourceTypeRelationship relationship ,
7495 IResourceLinkage linkage )
7596 {
7697 if ( linkage == null )
0 commit comments