/// <summary> /// Perform URI escaping, according to RFC 3986, on the specified <see cref="Uri" />. /// </summary> /// <param name="decoded">The <see cref="Uri" /> that needs to be escaped.</param> /// <param name="escaping">The rule set to follow when escaping.</param> /// <returns>The escaped string representation of the specified <see cref="Uri" />, according to RFC 3986.</returns> public static string UriEscape(this Uri decoded, UriEscaping escaping = UriEscaping.RFC3986) { switch (escaping) { case UriEscaping.RFC3986: return(decoded.UriEscapeRFC3986()); case UriEscaping.RFC2396: return(decoded.UriEscapeRFC2396()); default: throw new ArgumentOutOfRangeException(nameof(escaping), escaping, $"The specified {nameof(UriEscaping)} value is currently not supported."); } }
/// <summary> /// Perform URI escaping, according to RFC 3986, on the specified <see cref="string" /> representation of the <see cref="Uri" />. /// </summary> /// <param name="unescaped">The <see cref="String" /> representation of the <see cref="Uri" /> that needs to be encoded.</param> /// <param name="escaping">The rule set to follow when escaping.</param> /// <returns>The escaped string representation of the specified Uri <see cref="String" />, according to RFC 3986.</returns> public static string UriEscape(this string unescaped, UriEscaping escaping = UriEscaping.RFC3986) { return(unescaped == null ? null : new Uri(unescaped, UriKind.RelativeOrAbsolute).UriEscape(escaping)); }