Skip to content

Commit

Permalink
Merge pull request #1162 from json-api-dotnet/fix-definition-sort-in-…
Browse files Browse the repository at this point in the history
…type-hierarchy

Fixed crash in sort lambda from generic resource definition
  • Loading branch information
bkoelman authored Jun 24, 2022
2 parents 9af5eda + 174a599 commit 84106ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ private static (Expression? innerExpression, bool isCount) TryReadCount(Expressi

private Expression? ReadAttribute(Expression expression)
{
if (expression is MemberExpression memberExpression)
if (expression is MemberExpression { Expression: { } } memberExpression)
{
ResourceType resourceType = memberExpression.Member.Name == nameof(Identifiable<object>.Id) && memberExpression.Expression != null
? _resourceGraph.GetResourceType(memberExpression.Expression.Type)
: _resourceGraph.GetResourceType(memberExpression.Member.DeclaringType!);

ResourceType resourceType = _resourceGraph.GetResourceType(memberExpression.Expression.Type);
AttrAttribute? attribute = resourceType.FindAttributeByPropertyName(memberExpression.Member.Name);

if (attribute != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Can_convert_chain_of_ToOne_relationships_ending_in_attribute()
string[] expected =
{
"-fileEntries:content",
"fileSystemEntries:name",
"fileEntries:name",
"fileEntries:length",
"fileSystemEntries:parent.fileSystemEntries:name",
"fileSystemEntries:parent.fileSystemEntries:parent.fileSystemEntries:name"
Expand Down Expand Up @@ -103,7 +103,7 @@ public void Can_convert_chain_with_conversion_to_derived_types()
"fileSystemEntries:parent.fileEntries:content",
"count(directoryEntries:subdirectories)",
"count(fileSystemEntries:parent.directoryEntries:files)",
"-fileSystemEntries:name"
"-directoryEntries:name"
};

expression.ToFullString().Should().Be(string.Join(',', expected));
Expand Down

0 comments on commit 84106ac

Please sign in to comment.