/// <summary> /// Returns the filename component of the Uri. /// </summary> /// <param name="uri">A URI in the form 't4://extension/{id}/{relative-path-to-t4-file}'</param> public static string ParseFileName(System.Uri uri) { var segments = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped).Split(Path.AltDirectorySeparatorChar); if (segments.Length < 2) { return null; } return segments.Last(); }
internal static int UriGetHashCode(System.Uri uri, bool includeHostInComparison, bool includePortInComparison) { UriComponents components = UriComponents.Path | UriComponents.Scheme; if (includePortInComparison) { components |= UriComponents.Port; } if (includeHostInComparison) { components |= UriComponents.Host; } string str = uri.GetComponents(components, UriFormat.Unescaped); if ((str.Length > 0) && (str[str.Length - 1] != '/')) { str = str + "/"; } return StringComparer.OrdinalIgnoreCase.GetHashCode(str); }
internal static bool UriEquals(System.Uri u1, System.Uri u2, bool ignoreCase, bool includeHostInComparison, bool includePortInComparison) { if (u1.Equals(u2)) { return true; } if (u1.Scheme != u2.Scheme) { return false; } if (includePortInComparison && (u1.Port != u2.Port)) { return false; } if (includeHostInComparison && (string.Compare(u1.Host, u2.Host, StringComparison.OrdinalIgnoreCase) != 0)) { return false; } if (string.Compare(u1.AbsolutePath, u2.AbsolutePath, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { return true; } string components = u1.GetComponents(UriComponents.Path, UriFormat.Unescaped); string strB = u2.GetComponents(UriComponents.Path, UriFormat.Unescaped); int length = ((components.Length > 0) && (components[components.Length - 1] == '/')) ? (components.Length - 1) : components.Length; int num2 = ((strB.Length > 0) && (strB[strB.Length - 1] == '/')) ? (strB.Length - 1) : strB.Length; if (num2 != length) { return false; } return (string.Compare(components, 0, strB, 0, length, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0); }