@@ -43,23 +43,35 @@ public IResourceGraph Build()
43
43
44
44
var resourceGraph = new ResourceGraph ( resourceTypes ) ;
45
45
46
+ SetFieldTypes ( resourceGraph ) ;
46
47
SetRelationshipTypes ( resourceGraph ) ;
47
48
SetDirectlyDerivedTypes ( resourceGraph ) ;
48
49
49
50
return resourceGraph ;
50
51
}
51
52
53
+ private static void SetFieldTypes ( ResourceGraph resourceGraph )
54
+ {
55
+ foreach ( ResourceFieldAttribute field in resourceGraph . GetResourceTypes ( ) . SelectMany ( resourceType => resourceType . Fields ) )
56
+ {
57
+ field . Type = resourceGraph . GetResourceType ( field . Property . ReflectedType ! ) ;
58
+ }
59
+ }
60
+
52
61
private static void SetRelationshipTypes ( ResourceGraph resourceGraph )
53
62
{
54
63
foreach ( RelationshipAttribute relationship in resourceGraph . GetResourceTypes ( ) . SelectMany ( resourceType => resourceType . Relationships ) )
55
64
{
56
- relationship . LeftType = resourceGraph . GetResourceType ( relationship . LeftClrType ! ) ;
57
- ResourceType ? rightType = resourceGraph . FindResourceType ( relationship . RightClrType ! ) ;
65
+ Type rightClrType = relationship is HasOneAttribute
66
+ ? relationship . Property . PropertyType
67
+ : relationship . Property . PropertyType . GetGenericArguments ( ) [ 0 ] ;
68
+
69
+ ResourceType ? rightType = resourceGraph . FindResourceType ( rightClrType ) ;
58
70
59
71
if ( rightType == null )
60
72
{
61
- throw new InvalidConfigurationException ( $ "Resource type '{ relationship . LeftClrType } ' depends on " +
62
- $ "'{ relationship . RightClrType } ', which was not added to the resource graph.") ;
73
+ throw new InvalidConfigurationException ( $ "Resource type '{ relationship . LeftType . ClrType } ' depends on " +
74
+ $ "'{ rightClrType } ', which was not added to the resource graph.") ;
63
75
}
64
76
65
77
relationship . RightType = rightType ;
@@ -254,8 +266,6 @@ private IReadOnlyCollection<RelationshipAttribute> GetRelationships(Type resourc
254
266
{
255
267
relationship . Property = property ;
256
268
SetPublicName ( relationship , property ) ;
257
- relationship . LeftClrType = resourceClrType ;
258
- relationship . RightClrType = GetRelationshipType ( relationship , property ) ;
259
269
260
270
IncludeField ( relationshipsByName , relationship ) ;
261
271
}
@@ -270,14 +280,6 @@ private void SetPublicName(ResourceFieldAttribute field, PropertyInfo property)
270
280
field . PublicName ??= FormatPropertyName ( property ) ;
271
281
}
272
282
273
- private Type GetRelationshipType ( RelationshipAttribute relationship , PropertyInfo property )
274
- {
275
- ArgumentGuard . NotNull ( relationship , nameof ( relationship ) ) ;
276
- ArgumentGuard . NotNull ( property , nameof ( property ) ) ;
277
-
278
- return relationship is HasOneAttribute ? property . PropertyType : property . PropertyType . GetGenericArguments ( ) [ 0 ] ;
279
- }
280
-
281
283
private IReadOnlyCollection < EagerLoadAttribute > GetEagerLoads ( Type resourceClrType , int recursionDepth = 0 )
282
284
{
283
285
AssertNoInfiniteRecursion ( recursionDepth ) ;
0 commit comments