Table of Contents

Class ResourceType

Namespace
JsonApiDotNetCore.Configuration
Assembly
JsonApiDotNetCore.Annotations.dll

Metadata about the shape of a JSON:API resource in the resource graph.

[PublicAPI]
public sealed class ResourceType
Inheritance
ResourceType
Inherited Members

Constructors

ResourceType(string, ClientIdGenerationMode?, Type, Type, LinkTypes, LinkTypes, LinkTypes)

public ResourceType(string publicName, ClientIdGenerationMode? clientIdGeneration, Type clrType, Type identityClrType, LinkTypes topLevelLinks = LinkTypes.NotConfigured, LinkTypes resourceLinks = LinkTypes.NotConfigured, LinkTypes relationshipLinks = LinkTypes.NotConfigured)

Parameters

publicName string
clientIdGeneration ClientIdGenerationMode?
clrType Type
identityClrType Type
topLevelLinks LinkTypes
resourceLinks LinkTypes
relationshipLinks LinkTypes

ResourceType(string, ClientIdGenerationMode?, Type, Type, IReadOnlyCollection<AttrAttribute>?, IReadOnlyCollection<RelationshipAttribute>?, IReadOnlyCollection<EagerLoadAttribute>?, LinkTypes, LinkTypes, LinkTypes)

public ResourceType(string publicName, ClientIdGenerationMode? clientIdGeneration, Type clrType, Type identityClrType, IReadOnlyCollection<AttrAttribute>? attributes, IReadOnlyCollection<RelationshipAttribute>? relationships, IReadOnlyCollection<EagerLoadAttribute>? eagerLoads, LinkTypes topLevelLinks = LinkTypes.NotConfigured, LinkTypes resourceLinks = LinkTypes.NotConfigured, LinkTypes relationshipLinks = LinkTypes.NotConfigured)

Parameters

publicName string
clientIdGeneration ClientIdGenerationMode?
clrType Type
identityClrType Type
attributes IReadOnlyCollection<AttrAttribute>
relationships IReadOnlyCollection<RelationshipAttribute>
eagerLoads IReadOnlyCollection<EagerLoadAttribute>
topLevelLinks LinkTypes
resourceLinks LinkTypes
relationshipLinks LinkTypes

Properties

Attributes

Exposed resource attributes. See https://jsonapi.org/format/#document-resource-object-attributes. When using resource inheritance, this includes the attributes from base types.

public IReadOnlyCollection<AttrAttribute> Attributes { get; }

Property Value

IReadOnlyCollection<AttrAttribute>

BaseType

The base resource type, in case this is a derived type.

public ResourceType? BaseType { get; }

Property Value

ResourceType

ClientIdGeneration

Whether API clients are allowed or required to provide IDs when creating resources of this type. When null, the value from global options applies.

public ClientIdGenerationMode? ClientIdGeneration { get; }

Property Value

ClientIdGenerationMode?

ClrType

The CLR type of the resource.

public Type ClrType { get; }

Property Value

Type

DirectlyDerivedTypes

The resource types that directly derive from this one.

public IReadOnlySet<ResourceType> DirectlyDerivedTypes { get; }

Property Value

IReadOnlySet<ResourceType>

EagerLoads

Related entities that are not exposed as resource relationships. When using resource inheritance, this includes the eager-loads from base types.

public IReadOnlyCollection<EagerLoadAttribute> EagerLoads { get; }

Property Value

IReadOnlyCollection<EagerLoadAttribute>

Fields

Exposed resource attributes and relationships. See https://jsonapi.org/format/#document-resource-object-fields. When using resource inheritance, this includes the attributes and relationships from base types.

public IReadOnlyCollection<ResourceFieldAttribute> Fields { get; }

Property Value

IReadOnlyCollection<ResourceFieldAttribute>

IdentityClrType

The CLR type of the resource identity.

public Type IdentityClrType { get; }

Property Value

Type

PublicName

The publicly exposed resource name.

public string PublicName { get; }

Property Value

string

Configures which links to write in the relationship-level links object for all relationships of this resource type. Defaults to NotConfigured, which falls back to RelationshipLinks in global options. This can be overruled per relationship by setting Links.

public LinkTypes RelationshipLinks { get; }

Property Value

LinkTypes

In the process of building the resource graph, this value is set based on RelationshipLinks usage.

Relationships

Exposed resource relationships. See https://jsonapi.org/format/#document-resource-object-relationships. When using resource inheritance, this includes the relationships from base types.

public IReadOnlyCollection<RelationshipAttribute> Relationships { get; }

Property Value

IReadOnlyCollection<RelationshipAttribute>

Configures which links to write in the resource-level links object for this resource type. Defaults to NotConfigured, which falls back to ResourceLinks in global options.

public LinkTypes ResourceLinks { get; }

Property Value

LinkTypes

In the process of building the resource graph, this value is set based on ResourceLinks usage.

Configures which links to write in the top-level links object for this resource type. Defaults to NotConfigured, which falls back to TopLevelLinks in global options.

public LinkTypes TopLevelLinks { get; }

Property Value

LinkTypes

In the process of building the resource graph, this value is set based on TopLevelLinks usage.

Methods

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

FindAttributeByPropertyName(string)

public AttrAttribute? FindAttributeByPropertyName(string propertyName)

Parameters

propertyName string

Returns

AttrAttribute

FindAttributeByPublicName(string)

public AttrAttribute? FindAttributeByPublicName(string publicName)

Parameters

publicName string

Returns

AttrAttribute

FindRelationshipByPropertyName(string)

public RelationshipAttribute? FindRelationshipByPropertyName(string propertyName)

Parameters

propertyName string

Returns

RelationshipAttribute

FindRelationshipByPublicName(string)

public RelationshipAttribute? FindRelationshipByPublicName(string publicName)

Parameters

publicName string

Returns

RelationshipAttribute

GetAllConcreteDerivedTypes()

Returns all directly and indirectly non-abstract resource types that derive from this resource type.

public IReadOnlySet<ResourceType> GetAllConcreteDerivedTypes()

Returns

IReadOnlySet<ResourceType>

GetAttributeByPropertyName(string)

public AttrAttribute GetAttributeByPropertyName(string propertyName)

Parameters

propertyName string

Returns

AttrAttribute

GetAttributeByPublicName(string)

public AttrAttribute GetAttributeByPublicName(string publicName)

Parameters

publicName string

Returns

AttrAttribute

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetRelationshipByPropertyName(string)

public RelationshipAttribute GetRelationshipByPropertyName(string propertyName)

Parameters

propertyName string

Returns

RelationshipAttribute

GetRelationshipByPublicName(string)

public RelationshipAttribute GetRelationshipByPublicName(string publicName)

Parameters

publicName string

Returns

RelationshipAttribute

GetTypeOrDerived(Type)

Searches the tree of derived types to find a match for the specified clrType.

public ResourceType GetTypeOrDerived(Type clrType)

Parameters

clrType Type

Returns

ResourceType

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.