示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }