Esempio n. 1
0
        // Create a new instance of the link for a different resource type and copies
        // all link metadata for original.
        internal virtual ActionLink CreateCopyFor <TNewResourceType>()
            where TNewResourceType : class, IResource
        {
            var newResourceLink = new ActionLink();

            CopyTo <TNewResourceType>(newResourceLink);
            return(newResourceLink);
        }
Esempio n. 2
0
 // To reduce code duplication, a new link defined for one resource type can be applied
 // to another resource type.  This is common with resource view models.  The view model
 // represents the same resource but a different view of the information.
 internal virtual void CopyTo <TNewResourceType>(ActionLink actionLink)
     where TNewResourceType : class, IResource
 {
     actionLink.RelationName = RelationName;
     actionLink.Href         = Href;
     actionLink.HrefLang     = HrefLang;
     actionLink.Methods      = Methods;
     actionLink.Name         = Name;
     actionLink.Title        = Title;
     actionLink.Type         = Type;
     actionLink.Deprecation  = Deprecation?.CreateCopyFor <TNewResourceType>();
     actionLink.Profile      = Profile?.CreateCopyFor <TNewResourceType>();
 }
Esempio n. 3
0
        // Populate new instance of the link related with new resource type.
        internal override void CopyTo <TNewResourceType>(ActionLink actionLink)
        {
            base.CopyTo <TNewResourceType>(actionLink);

            var actionUrlLink = (ActionUrlLink)actionLink;

            actionUrlLink.Controller = Controller;
            actionUrlLink.Action     = Action;
            actionUrlLink.Methods    = Methods;

            var newResourceRouteValues = RouteValues.Select(rv => rv.CreateCopyFor <TNewResourceType>());

            actionUrlLink.SetRouteValues(newResourceRouteValues);
        }