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 } } }
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 } } }
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); }