Skip to content

Commit ce08b4f

Browse files
committed
style: DependentType, PrincipalType --> RightType, LeftType
1 parent 3af6f9b commit ce08b4f

19 files changed

+53
-66
lines changed

src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ protected virtual List<RelationshipAttribute> GetRelationships(Type entityType)
125125

126126
attribute.PublicRelationshipName = attribute.PublicRelationshipName ?? _resourceNameFormatter.FormatPropertyName(prop);
127127
attribute.InternalRelationshipName = prop.Name;
128-
attribute.DependentType = GetRelationshipType(attribute, prop);
129-
attribute.PrincipalType = entityType;
128+
attribute.RightType = GetRelationshipType(attribute, prop);
129+
attribute.LeftType = entityType;
130130
attributes.Add(attribute);
131131

132132
if (attribute is HasManyThroughAttribute hasManyThroughAttribute)
@@ -160,13 +160,13 @@ protected virtual List<RelationshipAttribute> GetRelationships(Type entityType)
160160
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a relationship id property to type {entityType} with name {leftIdPropertyName}");
161161

162162
// Article → ArticleTag.Tag
163-
hasManyThroughAttribute.RightProperty = throughProperties.SingleOrDefault(x => x.PropertyType == hasManyThroughAttribute.DependentType)
164-
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a navigation property to type {hasManyThroughAttribute.DependentType}");
163+
hasManyThroughAttribute.RightProperty = throughProperties.SingleOrDefault(x => x.PropertyType == hasManyThroughAttribute.RightType)
164+
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a navigation property to type {hasManyThroughAttribute.RightType}");
165165

166166
// ArticleTag.TagId
167167
var rightIdPropertyName = JsonApiOptions.RelatedIdMapper.GetRelatedIdPropertyName(hasManyThroughAttribute.RightProperty.Name);
168168
hasManyThroughAttribute.RightIdProperty = throughProperties.SingleOrDefault(x => x.Name == rightIdPropertyName)
169-
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a relationship id property to type {hasManyThroughAttribute.DependentType} with name {rightIdPropertyName}");
169+
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a relationship id property to type {hasManyThroughAttribute.RightType} with name {rightIdPropertyName}");
170170
}
171171
}
172172

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private static IOrderedQueryable<TSource> CallGenericOrderMethod<TSource>(IQuery
124124
return (IOrderedQueryable<TSource>)result;
125125
}
126126

127-
private static Expression GetFilterExpressionLambda(Expression left, Expression right, FilterOperation operation)
127+
private static Expression GetFilterExpressionLambda(Expression left, Expression right, FilterOperation operation)
128128
{
129129
Expression body;
130130
switch (operation)
@@ -259,7 +259,7 @@ private static IQueryable<TSource> CallGenericWhereMethod<TSource>(IQueryable<TS
259259
if (relationProperty == null)
260260
throw new ArgumentException($"'{filter.Relationship.InternalRelationshipName}' is not a valid relationship of '{concreteType}'");
261261

262-
var relatedType = filter.Relationship.DependentType;
262+
var relatedType = filter.Relationship.RightType;
263263
property = relatedType.GetProperty(filter.Attribute.InternalAttributeName);
264264
if (property == null)
265265
throw new ArgumentException($"'{filter.Attribute.InternalAttributeName}' is not a valid attribute of '{filter.Relationship.InternalRelationshipName}'");

src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public IResourceHookContainer GetResourceHookContainer(DependentType dependentTy
7171
}
7272

7373
/// <inheritdoc/>
74-
public IResourceHookContainer<TEntity> GetResourceHookContainer<TEntity>(ResourceHook hook = ResourceHook.None) where TEntity : class, IIdentifiable
74+
public IResourceHookContainer<TResource> GetResourceHookContainer<TResource>(ResourceHook hook = ResourceHook.None) where TResource : class, IIdentifiable
7575
{
76-
return (IResourceHookContainer<TEntity>)GetResourceHookContainer(typeof(TEntity), hook);
76+
return (IResourceHookContainer<TResource>)GetResourceHookContainer(typeof(TResource), hook);
7777
}
7878

7979
public IEnumerable LoadDbValues(PrincipalType entityTypeForRepository, IEnumerable entities, ResourceHook hook, params RelationshipAttribute[] inclusionChain)
@@ -89,12 +89,12 @@ public IEnumerable LoadDbValues(PrincipalType entityTypeForRepository, IEnumerab
8989
return (IEnumerable)Activator.CreateInstance(typeof(HashSet<>).MakeGenericType(entityTypeForRepository), values.Cast(entityTypeForRepository));
9090
}
9191

92-
public HashSet<TEntity> LoadDbValues<TEntity>(IEnumerable<TEntity> entities, ResourceHook hook, params RelationshipAttribute[] relationships) where TEntity : class, IIdentifiable
92+
public HashSet<TResource> LoadDbValues<TResource>(IEnumerable<TResource> entities, ResourceHook hook, params RelationshipAttribute[] relationships) where TResource : class, IIdentifiable
9393
{
94-
var entityType = typeof(TEntity);
95-
var dbValues = LoadDbValues(entityType, entities, hook, relationships)?.Cast<TEntity>();
94+
var entityType = typeof(TResource);
95+
var dbValues = LoadDbValues(entityType, entities, hook, relationships)?.Cast<TResource>();
9696
if (dbValues == null) return null;
97-
return new HashSet<TEntity>(dbValues);
97+
return new HashSet<TResource>(dbValues);
9898
}
9999

100100
public bool ShouldLoadDbValues(Type entityType, ResourceHook hook)
@@ -131,16 +131,16 @@ IHooksDiscovery GetHookDiscovery(Type entityType)
131131
return discovery;
132132
}
133133

134-
IEnumerable<TEntity> GetWhereAndInclude<TEntity, TId>(IEnumerable<TId> ids, RelationshipAttribute[] inclusionChain) where TEntity : class, IIdentifiable<TId>
134+
IEnumerable<TResource> GetWhereAndInclude<TResource, TId>(IEnumerable<TId> ids, RelationshipAttribute[] inclusionChain) where TResource : class, IIdentifiable<TId>
135135
{
136-
var repo = GetRepository<TEntity, TId>();
136+
var repo = GetRepository<TResource, TId>();
137137
var query = repo.Get().Where(e => ids.Contains(e.Id));
138138
return repo.Include(query, inclusionChain).ToList();
139139
}
140140

141-
IResourceReadRepository<TEntity, TId> GetRepository<TEntity, TId>() where TEntity : class, IIdentifiable<TId>
141+
IResourceReadRepository<TResource, TId> GetRepository<TResource, TId>() where TResource : class, IIdentifiable<TId>
142142
{
143-
return _genericProcessorFactory.GetProcessor<IResourceReadRepository<TEntity, TId>>(typeof(IResourceReadRepository<,>), typeof(TEntity), typeof(TId));
143+
return _genericProcessorFactory.GetProcessor<IResourceReadRepository<TResource, TId>>(typeof(IResourceReadRepository<,>), typeof(TResource), typeof(TId));
144144
}
145145

146146

src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship<T
8787
/// <inheritdoc />
8888
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type relatedType)
8989
{
90-
return this.Where(p => p.Key.DependentType == relatedType).ToDictionary(p => p.Key, p => p.Value);
90+
return this.Where(p => p.Key.RightType == relatedType).ToDictionary(p => p.Key, p => p.Value);
9191
}
9292

9393
/// <inheritdoc />

src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ void Traverse(NodeLayer currentLayer, ResourceHook target, Action<IResourceHookC
215215
void RecursiveBeforeRead(List<RelationshipAttribute> relationshipChain, ResourcePipeline pipeline, List<PrincipalType> calledContainers)
216216
{
217217
var relationship = relationshipChain.First();
218-
if (!calledContainers.Contains(relationship.DependentType))
218+
if (!calledContainers.Contains(relationship.RightType))
219219
{
220-
calledContainers.Add(relationship.DependentType);
221-
var container = _executorHelper.GetResourceHookContainer(relationship.DependentType, ResourceHook.BeforeRead);
220+
calledContainers.Add(relationship.RightType);
221+
var container = _executorHelper.GetResourceHookContainer(relationship.RightType, ResourceHook.BeforeRead);
222222
if (container != null)
223223
CallHook(container, ResourceHook.BeforeRead, new object[] { pipeline, true, null });
224224
}
@@ -306,7 +306,7 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, NodeLayer layer)
306306
/// the root layer is ALWAYS homogenous, so we safely assume
307307
/// that for every relationship to the previous layer, the
308308
/// principal type is the same.
309-
PrincipalType principalEntityType = currenEntitiesGrouped.First().Key.PrincipalType;
309+
PrincipalType principalEntityType = currenEntitiesGrouped.First().Key.LeftType;
310310
FireForAffectedImplicits(principalEntityType, currentEntitiesGroupedInverse, pipeline);
311311
}
312312
}
@@ -403,8 +403,8 @@ Dictionary<RelationshipAttribute, IEnumerable> ReplaceWithDbValues(Dictionary<Re
403403
{
404404
foreach (var key in prevLayerRelationships.Keys.ToList())
405405
{
406-
var replaced = prevLayerRelationships[key].Cast<IIdentifiable>().Select(entity => dbValues.Single(dbEntity => dbEntity.StringId == entity.StringId)).Cast(key.PrincipalType);
407-
prevLayerRelationships[key] = TypeHelper.CreateHashSetFor(key.PrincipalType, replaced);
406+
var replaced = prevLayerRelationships[key].Cast<IIdentifiable>().Select(entity => dbValues.Single(dbEntity => dbEntity.StringId == entity.StringId)).Cast(key.LeftType);
407+
prevLayerRelationships[key] = TypeHelper.CreateHashSetFor(key.LeftType, replaced);
408408
}
409409
return prevLayerRelationships;
410410
}

src/JsonApiDotNetCore/Hooks/Traversal/RelationshipProxy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RelationshipProxy
3131
/// Identifiable) or it is the righthand side (when the jointable is not identifiable)
3232
/// </summary>
3333
public Type DependentType { get; private set; }
34-
public Type PrincipalType { get { return Attribute.PrincipalType; } }
34+
public Type PrincipalType { get { return Attribute.LeftType; } }
3535
public bool IsContextRelation { get; private set; }
3636

3737
public RelationshipAttribute Attribute { get; set; }

src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ DependentType GetDependentTypeFromRelationship(RelationshipAttribute attr)
270270
{
271271
return throughAttr.ThroughType;
272272
}
273-
return attr.DependentType;
273+
return attr.RightType;
274274
}
275275

276276
void AddToRelationshipGroup(Dictionary<RelationshipProxy, List<IIdentifiable>> target, RelationshipProxy proxy, IEnumerable<IIdentifiable> newEntities)

src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ public override object GetValue(object entity)
8585

8686
if (throughEntities == null)
8787
// return an empty list for the right-type of the property.
88-
return TypeHelper.CreateListFor(DependentType);
88+
return TypeHelper.CreateListFor(RightType);
8989

9090
// the right entities are included on the navigation/through entities. Extract and return them.
9191
var rightEntities = new List<IIdentifiable>();
9292
foreach (var rightEntity in (IList)throughEntities)
9393
rightEntities.Add((IIdentifiable)RightProperty.GetValue(rightEntity));
9494

95-
return rightEntities.Cast(DependentType);
95+
return rightEntities.Cast(RightType);
9696
}
9797

9898

src/JsonApiDotNetCore/Models/Annotation/RelationshipAttribute.cs

+4-17
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ protected RelationshipAttribute(string publicName, Link relationshipLinks, bool
2323
public string InternalRelationshipName { get; internal set; }
2424
public string InverseNavigation { get; internal set; }
2525

26-
/// <summary>
27-
/// The related entity type. This does not necessarily match the navigation property type.
28-
/// In the case of a HasMany relationship, this value will be the generic argument type.
29-
/// </summary>
30-
///
31-
/// <example>
32-
/// <code>
33-
/// public List&lt;Tag&gt; Tags { get; sit; } // Type => Tag
34-
/// </code>
35-
/// </example>
36-
[Obsolete("Use property DependentType")]
37-
public Type Type { get { return DependentType; } internal set { DependentType = value; } }
38-
3926
/// <summary>
4027
/// The related entity type. This does not necessarily match the navigation property type.
4128
/// In the case of a HasMany relationship, this value will be the generic argument type.
@@ -48,12 +35,12 @@ protected RelationshipAttribute(string publicName, Link relationshipLinks, bool
4835
/// public List&lt;Tag&gt; Tags { get; set; } // Type => Tag
4936
/// </code>
5037
/// </example>
51-
public Type DependentType { get; internal set; }
38+
public Type RightType { get; internal set; }
5239

5340
/// <summary>
5441
/// The parent entity type. The technical language as used in EF Core is used here (dependent vs principal).
5542
/// </summary>
56-
public Type PrincipalType { get; internal set; }
43+
public Type LeftType { get; internal set; }
5744

5845
public bool IsHasMany => GetType() == typeof(HasManyAttribute) || GetType().Inherits(typeof(HasManyAttribute));
5946
public bool IsHasOne => GetType() == typeof(HasOneAttribute);
@@ -84,9 +71,9 @@ public override bool Equals(object obj)
8471
bool equalRelationshipName = PublicRelationshipName.Equals(attr.PublicRelationshipName);
8572

8673
bool equalPrincipalType = true;
87-
if (PrincipalType != null)
74+
if (LeftType != null)
8875
{
89-
equalPrincipalType = PrincipalType.Equals(attr.PrincipalType);
76+
equalPrincipalType = LeftType.Equals(attr.LeftType);
9077
}
9178
return IsHasMany == attr.IsHasMany && equalRelationshipName && equalPrincipalType;
9279
}

src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected AttrAttribute GetAttribute(string target, RelationshipAttribute relati
4848
{
4949
AttrAttribute attribute;
5050
if (relationship != null)
51-
attribute = _resourceGraph.GetAttributes(relationship.DependentType).FirstOrDefault(a => a.Is(target));
51+
attribute = _resourceGraph.GetAttributes(relationship.RightType).FirstOrDefault(a => a.Is(target));
5252
else
5353
attribute = _requestResource.Attributes.FirstOrDefault(attr => attr.Is(target));
5454

src/JsonApiDotNetCore/QueryParameterServices/IncludeService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void ParseChain(string chain)
5252
throw CannotIncludeError(resourceContext, relationshipName);
5353

5454
parsedChain.Add(relationship);
55-
resourceContext = _resourceGraph.GetResourceContext(relationship.DependentType);
55+
resourceContext = _resourceGraph.GetResourceContext(relationship.RightType);
5656
}
5757
_includedChains.Add(parsedChain);
5858
}

src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public List<AttrAttribute> Get(RelationshipAttribute relationship = null)
3939
_selectedRelationshipFields.TryGetValue(relationship, out var fields);
4040
return fields;
4141
}
42-
42+
4343
/// <inheritdoc/>
4444
public virtual void Parse(KeyValuePair<string, StringValues> queryParameter)
4545
{ // expected: articles?fields=prop1,prop2
@@ -83,10 +83,10 @@ public virtual void Parse(KeyValuePair<string, StringValues> queryParameter)
8383
/// </summary>
8484
private void RegisterRelatedResourceField(string field, RelationshipAttribute relationship)
8585
{
86-
var relationProperty = _resourceGraph.GetResourceContext(relationship.DependentType);
86+
var relationProperty = _resourceGraph.GetResourceContext(relationship.RightType);
8787
var attr = relationProperty.Attributes.SingleOrDefault(a => a.Is(field));
8888
if (attr == null)
89-
throw new JsonApiException(400, $"'{relationship.DependentType.Name}' does not contain '{field}'.");
89+
throw new JsonApiException(400, $"'{relationship.RightType.Name}' does not contain '{field}'.");
9090

9191
if (!_selectedRelationshipFields.TryGetValue(relationship, out var registeredFields))
9292
_selectedRelationshipFields.Add(relationship, registeredFields = new List<AttrAttribute>());

src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override void AfterProcessField(IIdentifiable entity, IResourceField f
7171
}
7272
else if (field is HasManyAttribute hasManyAttr)
7373
{ // add attributes and relationships of a parsed HasMany relationship
74-
var values = TypeHelper.CreateListFor(hasManyAttr.DependentType);
74+
var values = TypeHelper.CreateListFor(hasManyAttr.RightType);
7575
foreach (var rio in data.ManyData)
7676
values.Add(ParseIncludedRelationship(hasManyAttr, rio));
7777

@@ -84,7 +84,7 @@ protected override void AfterProcessField(IIdentifiable entity, IResourceField f
8484
/// </summary>
8585
private IIdentifiable ParseIncludedRelationship(RelationshipAttribute relationshipAttr, ResourceIdentifierObject relatedResourceIdentifier)
8686
{
87-
var relatedInstance = relationshipAttr.DependentType.New<IIdentifiable>();
87+
var relatedInstance = relationshipAttr.RightType.New<IIdentifiable>();
8888
relatedInstance.StringId = relatedResourceIdentifier.Id;
8989

9090
var includedResource = GetLinkedResource(relatedResourceIdentifier);
@@ -93,7 +93,7 @@ private IIdentifiable ParseIncludedRelationship(RelationshipAttribute relationsh
9393

9494
var contextEntity = _provider.GetResourceContext(relatedResourceIdentifier.Type);
9595
if (contextEntity == null)
96-
throw new InvalidOperationException($"Included type '{relationshipAttr.DependentType}' is not a registered json:api resource.");
96+
throw new InvalidOperationException($"Included type '{relationshipAttr.RightType}' is not a registered json:api resource.");
9797

9898
SetAttributes(relatedInstance, includedResource.Attributes, contextEntity.Attributes);
9999
SetRelationships(relatedInstance, includedResource.Relationships, contextEntity.Relationships);

src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void SetNavigation(IIdentifiable entity, HasOneAttribute attr, string re
213213
}
214214
else
215215
{
216-
var relatedInstance = attr.DependentType.New<IIdentifiable>();
216+
var relatedInstance = attr.RightType.New<IIdentifiable>();
217217
relatedInstance.StringId = relatedId;
218218
attr.SetValue(entity, relatedInstance);
219219
}
@@ -230,11 +230,11 @@ private object SetHasManyRelationship(IIdentifiable entity,
230230
{ // if the relationship is set to null, no need to set the navigation property to null: this is the default value.
231231
var relatedResources = relationshipData.ManyData.Select(rio =>
232232
{
233-
var relatedInstance = attr.DependentType.New<IIdentifiable>();
233+
var relatedInstance = attr.RightType.New<IIdentifiable>();
234234
relatedInstance.StringId = rio.Id;
235235
return relatedInstance;
236236
});
237-
var convertedCollection = TypeHelper.ConvertCollection(relatedResources, attr.DependentType);
237+
var convertedCollection = TypeHelper.ConvertCollection(relatedResources, attr.RightType);
238238
attr.SetValue(entity, convertedCollection);
239239
}
240240

src/JsonApiDotNetCore/Serialization/Server/ResponseSerializerFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public IJsonApiSerializer GetSerializer()
4444
private Type GetDocumentPrimaryType()
4545
{
4646
if (_currentRequest.RequestRelationship != null && !_currentRequest.IsRelationshipPath)
47-
return _currentRequest.RequestRelationship.DependentType;
47+
return _currentRequest.RequestRelationship.RightType;
4848

4949
return _currentRequest.GetRequestResource()?.ResourceType;
5050
}

0 commit comments

Comments
 (0)