示例#1
0
        public ILinkObject ResolveTemplated(Func <UriTemplate, string> hrefResolver)
        {
            if (!Templated)
            {
                throw new InvalidOperationException("Cannot resolve a non-Templated link");
            }

            var template = new UriTemplate(Template);
            var href     = hrefResolver(template);

            var link = new LinkObject
            {
                Rel         = Rel,
                Templated   = false,
                Deprecation = Deprecation,
                HrefLang    = HrefLang,
                Name        = Name,
                Profile     = Profile,
                Title       = Title,
                Type        = Type
            };

            link.SetHref(href);

            return(link);
        }
示例#2
0
        private static LinkObject ParseLinkObject(JObject outer, string rel)
        {
            var link = new LinkObject {
                Rel = rel
            };

            foreach (var inner in outer.Properties())
            {
                var value = inner.Value.ToString();

                if (string.IsNullOrEmpty(value))
                {
                    continue; // nothing to assign, just leave the default value ...
                }
                switch (inner.Name.ToLowerInvariant())
                {
                case "href":
                    link.Href = TryCreateUri(value, UriKind.RelativeOrAbsolute);
                    break;

                case "templated":
                    link.Templated = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "type":
                    link.Type = value;
                    break;

                case "deprication":
                    link.Deprecation = TryCreateUri(value, UriKind.Absolute);
                    break;

                case "name":
                    link.Name = value;
                    break;

                case "profile":
                    link.Profile = TryCreateUri(value, UriKind.Absolute);
                    break;

                case "title":
                    link.Title = value;
                    break;

                case "hreflang":
                    link.HrefLang = value;
                    break;
                }
            }

            return(link);
        }
示例#3
0
		public ILinkObject ResolveTemplated(Func<UriTemplate, string> hrefResolver)
		{
			if (!Templated)
				throw new InvalidOperationException("Cannot resolve a non-Templated link");

			var template = new UriTemplate(Template);
			var href = hrefResolver(template);

			var link = new LinkObject
			{
				Rel = Rel,
				Templated = false,
				Deprecation = Deprecation,
				HrefLang = HrefLang,
				Name = Name,
				Profile = Profile,
				Title = Title,
				Type = Type
			};

			link.SetHref(href);

			return link;
		}
示例#4
0
        private static LinkObject ParseLinkObject(JObject outer, string rel)
        {
            var link = new LinkObject {
                Rel = rel
            };
            string href = null;

            foreach (var inner in outer.Properties())
            {
                var value = inner.Value.ToString();

                if (string.IsNullOrEmpty(value))
                {
                    continue;                     // nothing to assign, just leave the default value ...
                }
                var attribute = inner.Name.ToLowerInvariant();

                switch (attribute)
                {
                case "href":
                    href = value;
                    break;

                case "templated":
                    link.Templated = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "type":
                    link.Type = value;
                    break;

                case "deprication":
                    link.SetDeprecation(value);
                    break;

                case "name":
                    link.Name = value;
                    break;

                case "profile":
                    link.SetProfile(value);
                    break;

                case "title":
                    link.Title = value;
                    break;

                case "hreflang":
                    link.HrefLang = value;
                    break;

                default:
                    throw new NotSupportedException("Unsupported link attribute encountered: " + attribute);
                }
            }

            if (link.Templated)
            {
                link.Template = href;
            }
            else
            {
                link.SetHref(href);
            }

            return(link);
        }