// Called for action link consisting of a string interpolation format based on resource properties. private Link SetLinkUrl(ResourceContext context, StringFormattedLink resourceLink) { var link = new Link { Href = resourceLink.FormatUrl(context.Resource), Methods = resourceLink.Methods.ToArray() }; UpdateLinkDescriptorsAndResource(context, resourceLink, link); return(link); }
public StringFormattedLink <TResource> BuildResourceUrl(HttpMethod httpMethod, Expression <Func <TResource, string> > resourceUrl) { if (resourceUrl == null) { throw new ArgumentNullException(nameof(resourceUrl), "Resource Delegate cannot be null."); } var resourceLink = new StringFormattedLink <TResource>(resourceUrl); var linkDescriptor = new LinkDescriptor <TResource>(resourceLink); linkDescriptor.SetMethod(httpMethod); return(resourceLink); }
/// <summary> /// Create a named link based on string interpolation based on resource properties. /// </summary> /// <param name="relName">The relation name.</param> /// <param name="httpMethod">The HTTP method used to invoke URI.</param> /// <param name="resourceUrl">Function delegate passed the resource during link resolution and /// returns a populated URI or partial populated URI (i.e. Template) based on the properties /// of the passed resourced.</param> /// <returns>Object used to add optional metadata to the created link.</returns> public LinkDescriptor <TResource> Href(string relName, HttpMethod httpMethod, Expression <Func <TResource, string> > resourceUrl) { if (string.IsNullOrWhiteSpace(relName)) { throw new ArgumentException( "Relation Name not specified.", nameof(relName)); } if (resourceUrl == null) { throw new ArgumentNullException(nameof(resourceUrl), "Resource Delegate cannot be null."); } var resourceLink = new StringFormattedLink <TResource>(resourceUrl); var linkDescriptor = new LinkDescriptor <TResource>(resourceLink); AddResourceLink(resourceLink); linkDescriptor.SetRelName(relName); linkDescriptor.SetMethod(httpMethod); return(linkDescriptor); }