Esempio n. 1
0
        /// <summary>Returns the full and complete URL as a single string.</summary>
        public static string ToFull(this IHttpUrl url)
        {
            var sb = new StringBuilder(256);

            sb.Append(url.Https ? "https://" : "http://");
            sb.Append(url.Domain);
            if (url.ParentDomains != null)
            {
                for (int i = url.ParentDomains.Length - 1; i >= 0; i--)
                {
                    sb.Append(url.ParentDomains[i]);
                }
            }
            if ((!url.Https && url.Port != 80) || (url.Https && url.Port != 443))
            {
                sb.Append(':');
                sb.Append(url.Port);
            }
            if (url.ParentPaths != null)
            {
                for (int i = 0; i < url.ParentPaths.Length; i++)
                {
                    sb.Append(url.ParentPaths[i]);
                }
            }
            sb.Append(url.Path);
            url.AppendQueryString(sb, first: true);
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        ///     Returns the full path and query string of the specified URL (the part that follows the domain).</summary>
        /// <remarks>
        ///     This is intended to be used as <c>href</c> attribute values in <c>&lt;a&gt;</c> tags as it works well for an
        ///     absolute path within the same domain.</remarks>
        public static string ToHref(this IHttpUrl url)
        {
            var sb = new StringBuilder(128);

            for (int i = 0; i < url.ParentPaths.Length; i++)
            {
                sb.Append(url.ParentPaths[i]);
            }
            sb.Append(url.Path);
            url.AppendQueryString(sb, first: true);
            return(sb.ToString());
        }
Esempio n. 3
0
 public virtual void AppendQueryString(StringBuilder sb, bool first)
 {
     _source.AppendQueryString(sb, first);
 }