/// <summary>
        /// Gets the <see cref="Uri"/> without the query string.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="source">The source <see cref="Url"/> from which to copy the query string.</param>
        /// <returns>The <see cref="Url"/> with the modified query string.</returns>
        public Url Evaluate(IMansionContext context, Url source)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (source == null)
                throw new ArgumentNullException("source");

            var clone = source.Clone();
            clone.QueryString.Clear();
            clone.Fragment = string.Empty;
            return clone;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies the query string from <paramref name="source"/> to <paramref name="target"/>.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="source">The source <see cref="Url"/> from which to copy the query string.</param>
        /// <param name="target">The target <see cref="Url"/> to which to copy the query string.</param>
        /// <returns>The <see cref="Url"/> with the modified query string.</returns>
        public Url Evaluate(IMansionContext context, Url source, Url target)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (source == null)
                throw new ArgumentNullException("source");
            if (target == null)
                throw new ArgumentNullException("target");

            var clone = target.Clone();

            foreach (var entry in source.QueryString)
                clone.QueryString[entry.Key] = entry.Value;

            return clone;
        }
        /// <summary>
        /// Changes the value of an attribute in the query string.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="url">The <see cref="Url"/> which to change.</param>
        /// <param name="dataspace">The <see cref="IPropertyBag"/> which to add to the query string.</param>
        /// <returns>The <see cref="Url"/> with the modified query string.</returns>
        public Url Evaluate(IMansionContext context, Url url, IPropertyBag dataspace)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (url == null)
                throw new ArgumentNullException("url");
            if (dataspace == null)
                throw new ArgumentNullException("dataspace");

            var modifiableUri = url.Clone();

            // merge the dataspace
            foreach (var entry in dataspace)
                modifiableUri.QueryString[entry.Key] = conversionService.Convert<string>(context, entry.Value);

            // return the url
            return modifiableUri;
        }
        /// <summary>
        /// Changes the value of an attribute in the query string.
        /// </summary>
        /// <param name="context">The <see cref="IMansionContext"/>.</param>
        /// <param name="url">The <see cref="Url"/> which to change.</param>
        /// <param name="parameterName">The name of the parmeters which to set.</param>
        /// <param name="value">The value of the parameters.</param>
        /// <returns>The <see cref="Url"/> with the modified query string.</returns>
        public Url Evaluate(IMansionContext context, Url url, string parameterName, string value)
        {
            // validate arguments
            if (context == null)
                throw new ArgumentNullException("context");
            if (url == null)
                throw new ArgumentNullException("url");
            if (string.IsNullOrEmpty(parameterName))
                throw new ArgumentNullException("parameterName");

            var modifiableUri = url.Clone();

            // set the property or clear it when already in the query string
            if (!string.IsNullOrEmpty(value))
                modifiableUri.QueryString[parameterName] = value;
            else if (modifiableUri.QueryString.ContainsKey(parameterName))
                modifiableUri.QueryString.Remove(parameterName);

            // return the url
            return modifiableUri;
        }