private static DomReadOnlyResource AddDomReadOnlyResource(DomDocument domDocument, IContainerNode <DomNodeType> domParentNode, Resource apiResource) { Contract.Requires(domDocument != null); Contract.Requires(domParentNode != null); Contract.Requires(apiResource != null); // Find metadata based on the JsonApi resource. var apiResourceType = apiResource.Type; var serviceModel = domDocument.ServiceModel; var resourceType = serviceModel.GetResourceType(apiResourceType); // Create/Add DOM read-only resource node to the parent node. var clrResource = resourceType.CreateClrObject(); var domReadOnlyResource = domParentNode.CreateAndAddNode(() => DomReadOnlyResource.Create(apiResource, clrResource)); // Map the incoming JsonApi resource to the created CLR resource. resourceType.MapApiMetaToClrResource(clrResource, apiResource); resourceType.MapApiIdToClrResource(clrResource, apiResource); resourceType.MapApiAttributesToClrResource(clrResource, apiResource, serviceModel); resourceType.MapApiRelationshipsToClrResource(clrResource, apiResource); resourceType.MapApiLinksToClrResource(clrResource, apiResource); return(domReadOnlyResource); }
// PUBLIC METHODS /////////////////////////////////////////////////// #region Methods public static TNode CreateAndAddNode <TNodeType, TNode>(this IContainerNode <TNodeType> containerNode) where TNode : Node <TNodeType>, new() { Contract.Requires(containerNode != null); return(containerNode.CreateAndAddNode(() => new TNode())); }
private static DomReadOnlyResourceIdentifier AddDomReadOnlyResourceIdentifier(DomDocument domDocument, IContainerNode <DomNodeType> domParentNode, ResourceIdentifier apiResourceIdentifier) { Contract.Requires(domDocument != null); Contract.Requires(domParentNode != null); Contract.Requires(apiResourceIdentifier != null); // Find metadata based on the JsonApi resource. var apiResourceType = apiResourceIdentifier.Type; var resourceType = domDocument.ServiceModel.GetResourceType(apiResourceType); var clrResourceType = resourceType.ClrType; // Create/Add DOM read-only resource identifier node to the parent node. var domReadOnlyResourceIdentifier = domParentNode.CreateAndAddNode(() => DomReadOnlyResourceIdentifier.Create(apiResourceIdentifier, clrResourceType)); return(domReadOnlyResourceIdentifier); }