23 using System.Collections.Generic;
27 namespace Ntp.Common.Web
31 public static Uri
Append(
this Uri uri, params
string[] paths)
36 GetBase(uri, out basePath, out uriKind);
37 string resPath = paths.Aggregate(
39 (current, path) => $
"{current.TrimEnd('/')}/{path.TrimStart('/')}");
40 Uri newUri =
new Uri(resPath, uriKind);
45 public static Uri
Append(
this Uri uri, Uri relativeUri, params
string[] paths)
47 string relativeUriText = relativeUri.IsAbsoluteUri
48 ? relativeUri.AbsolutePath
49 : relativeUri.ToString();
50 var list =
new List<string> {relativeUriText};
52 return uri.Append(list.ToArray());
55 public static Uri
Append(
this Uri uri, Uri relativeUri,
string path)
57 string relativeUriText = relativeUri.IsAbsoluteUri
58 ? relativeUri.AbsolutePath
59 : relativeUri.ToString();
60 var list =
new List<string> {relativeUriText, path};
61 return uri.Append(list.ToArray());
69 GetBase(uri, out basePath, out uriKind);
70 basePath = basePath.TrimEnd(
'/') + extension;
71 Uri newUri =
new Uri(basePath, uriKind);
78 StringBuilder
b =
new StringBuilder();
79 b.AppendLine($
"ToString(): {uri}");
80 b.AppendLine($
"IsAbsoluteUri: {uri.IsAbsoluteUri}");
81 b.AppendLine($
"OriginalString: {uri.OriginalString}");
83 if (uri.IsAbsoluteUri)
85 b.AppendLine($
"AbsolutePath: {uri.AbsolutePath}");
86 b.AppendLine($
"AbsoluteUri: {uri.AbsoluteUri}");
87 b.AppendLine($
"Authority: {uri.Authority}");
88 b.AppendLine($
"DnsSafeHost: {uri.DnsSafeHost}");
89 b.AppendLine($
"Fragment: {uri.Fragment}");
90 b.AppendLine($
"Host: {uri.Host}");
91 b.AppendLine($
"HostNameType: {uri.HostNameType}");
92 b.AppendLine($
"IsDefaultPort {uri.IsDefaultPort}");
93 b.AppendLine($
"IsFile: {uri.IsFile}");
94 b.AppendLine($
"IsLoopback: {uri.IsLoopback}");
95 b.AppendLine($
"IsUnc: {uri.IsUnc}");
96 b.AppendLine($
"LocalPath: {uri.LocalPath}");
97 b.AppendLine($
"PathAndQuery: {uri.PathAndQuery}");
98 b.AppendLine($
"Port: {uri.Port}");
99 b.AppendLine($
"Query: {uri.Query}");
100 b.AppendLine($
"Scheme: {uri.Scheme}");
101 b.AppendLine($
"Segments: {uri.Segments}");
102 b.AppendLine($
"UserEscaped: {uri.UserEscaped}");
103 b.AppendLine($
"UserInfo: {uri.UserInfo}");
111 return Uri.EscapeUriString(uri.ToString());
114 private static void GetBase(Uri uri, out
string basePath, out UriKind uriKind)
116 string orig = uri.OriginalString.TrimStart();
117 if (orig.StartsWith(
"/") && !orig.StartsWith(
"//"))
119 basePath = uri.IsAbsoluteUri
122 uriKind = UriKind.Relative;
126 basePath = uri.ToString();
127 uriKind = UriKind.Absolute;
static void GetBase(Uri uri, out string basePath, out UriKind uriKind)
static Uri Append(this Uri uri, params string[] paths)
static Uri Append(this Uri uri, Uri relativeUri, params string[] paths)
static Uri Append(this Uri uri, Uri relativeUri, string path)
static string ToHtmlString(this Uri uri)
static string DebugInfo(this Uri uri)
static Uri AppendExtension(this Uri uri, string extension)