Skip to content

Add 'GetPublicAttributeName' to Context Graph #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/JsonApiDotNetCore/Internal/ContextGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace JsonApiDotNetCore.Internal
public interface IContextGraph
{
/// <summary>
/// Gets the value of the navigation property, defined by the relationshipName,
/// Gets the value of the navigation property, defined by the relationshipName,
/// on the provided instance.
/// </summary>
/// <param name="resource">The resource instance</param>
Expand Down Expand Up @@ -42,6 +42,12 @@ public interface IContextGraph
/// </summary>
ContextEntity GetContextEntity(Type entityType);

/// <summary>
/// Get the public attribute name for a type based on the internal attribute name.
/// </summary>
/// <param name="internalAttributeName">The internal attribute name for a <see cref="Attr" />.</param>
string GetPublicAttributeName<TParent>(string internalAttributeName);

/// <summary>
/// Was built against an EntityFrameworkCore DbContext ?
/// </summary>
Expand Down Expand Up @@ -111,5 +117,13 @@ public string GetRelationshipName<TParent>(string relationshipName)
.SingleOrDefault(r => r.Is(relationshipName))
?.InternalRelationshipName;
}
}

public string GetPublicAttributeName<TParent>(string internalAttributeName)
{
return GetContextEntity(typeof(TParent))
.Attributes
.Single(a => a.InternalAttributeName == internalAttributeName)
.PublicAttributeName;
}
}
}