private static Link CreateLink(Type type, LinkAttributeBase linkAttribute) { string uriTemplate; if (string.IsNullOrWhiteSpace(linkAttribute.UriTemplate)) { try { uriTemplate = UriTemplateAttribute.GetAllTemplates(type).Single(); } catch (InvalidOperationException) { throw new InvalidOperationException("Must specify a UriTemplate for LinkAttribute where more than one UriTemplateAttribute is used."); } } else { uriTemplate = linkAttribute.UriTemplate; } return new Link(type, uriTemplate, linkAttribute.GetRel(), linkAttribute.Type, linkAttribute.Title); }
private static ILinkBuilder CreateBuilder(Type modelType) { var linkList = new List <Link>(); foreach (var type in ExportedTypeHelper.FromCurrentAppDomain(LinkAttributeBase.Exists)) { var attributesForModel = LinkAttributeBase.Get(type, modelType); if (attributesForModel.Count == 0) { continue; } linkList.AddRange(attributesForModel.Select(a => CreateLink(type, a))); } if (linkList.Count > 0) { return(new LinkBuilder(linkList)); } return(LinkBuilder.Empty); }
private static Link CreateLink(Type type, LinkAttributeBase linkAttribute) { string uriTemplate; if (string.IsNullOrWhiteSpace(linkAttribute.UriTemplate)) { try { uriTemplate = UriTemplateAttribute.GetAllTemplates(type).Single(); } catch (InvalidOperationException) { throw new InvalidOperationException("Must specify a UriTemplate for LinkAttribute where more than one UriTemplateAttribute is used."); } } else { uriTemplate = linkAttribute.UriTemplate; } return(new Link(type, uriTemplate, linkAttribute.GetRel(), linkAttribute.Type, linkAttribute.Title)); }