コード例 #1
0
        protected static void Append <T>(IResource resource, IHypermediaResolver resolver) where T : class, IResource
        // called using reflection ...
        {
            var typed = resource as T;

            if (typed == null)
            {
                throw new ArgumentOutOfRangeException(nameof(resource), "resource must be of type " + typeof(T));
            }

            IHypermediaAppender <T> appender   = resolver.ResolveAppender(typed);
            List <Link>             configured = resolver.ResolveLinks(typed).ToList();
            Link link = resolver.ResolveSelf(typed);

            if (link != null)
            {
                configured.Insert(0, link);
            }

            if (configured.Count > 0 && (appender != null))
            {
                if (typed.Links == null)
                {
                    typed.Links = new List <Link>(); // make sure resource.Links.Add() can safely be called inside the appender
                }
                appender.Append(typed, configured);

                if ((typed.Links != null) && !typed.Links.Any())
                {
                    typed.Links = null; // prevent _links property serialization
                }
            }
        }
コード例 #2
0
        protected static void Append <T>(IResource resource, IHypermediaResolver resolver) where T : class, IResource
        // called using reflection ...
        {
            var typed = resource as T;

            var appender   = resolver.ResolveAppender(typed);
            var configured = resolver.ResolveLinks(typed).ToList();
            var link       = resolver.ResolveSelf(typed);

            if (link != null)
            {
                configured.Insert(0, link);
            }

            if (configured.Any() && (appender != null))
            {
                if (typed.Links == null)
                {
                    typed.Links = new List <Link>();                // make sure resource.Links.Add() can safely be called inside the appender
                }
                appender.Append(typed, configured);

                if ((typed.Links != null) && !typed.Links.Any())
                {
                    typed.Links = null;                 // prevent _links property serialisation
                }
            }
        }
コード例 #3
0
ファイル: Representation.cs プロジェクト: zlich/WebApi.Hal
        protected static void Append <T>(IResource resource, IHypermediaResolver resolver) where T : class, IResource // called using reflection ...
        {
            var typed = resource as T;

            var appender   = resolver.ResolveAppender(typed);
            var configured = resolver.ResolveLinks(typed).ToList();

            configured.Insert(0, resolver.ResolveSelf(typed));

            appender.Append(typed, configured);
        }