System.UriExtensions.ToRelativeUri C# (CSharp) Méthode

ToRelativeUri() public static méthode

Converts a given uri to a relative one.
public static ToRelativeUri ( this uri ) : Uri
uri this Uri to be converted.
Résultat Uri
        public static Uri ToRelativeUri(this Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            if (!uri.IsAbsoluteUri)
            {
                return uri;
            }

            string result = uri.ToString();
            result = result.Substring(uri.ToString().IndexOf(uri.Host) + uri.Host.Length);
            if (result[0] == ':')
            {
                result = result.Substring(1 + uri.Port.ToString().Length);
            }

            return new Uri(result, UriKind.Relative);
        }