| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.IdentityModel |
| | | 7 | | { |
| | | 8 | | internal static class UriUtil |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Determines whether a URI is valid and can be created using the specified UriKind. |
| | | 12 | | /// Uri.TryCreate is used here, which is more lax than Uri.IsWellFormedUriString. |
| | | 13 | | /// The reason we use this function is because IsWellFormedUriString will reject valid URIs if they are IPv6 or |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="uriString">The string to check.</param> |
| | | 16 | | /// <param name="uriKind">The type of URI (usually UriKind.Absolute)</param> |
| | | 17 | | /// <returns>True if the URI is valid, false otherwise.</returns> |
| | | 18 | | public static bool CanCreateValidUri(string uriString, UriKind uriKind) |
| | | 19 | | { |
| | | 20 | | Uri tempUri; |
| | | 21 | | |
| | 0 | 22 | | return TryCreateValidUri(uriString, uriKind, out tempUri); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Determines whether a URI is valid and can be created using the specified UriKind. |
| | | 27 | | /// Uri.TryCreate is used here, which is more lax than Uri.IsWellFormedUriString. |
| | | 28 | | /// The reason we use this function is because IsWellFormedUriString will reject valid URIs if they are IPv6 or |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="uriString">The string to check.</param> |
| | | 31 | | /// <param name="uriKind">The type of URI (usually UriKind.Absolute)</param> |
| | | 32 | | /// <param name="result">An out param representing the created URI</param> |
| | | 33 | | /// <returns>True if the URI is valid, false otherwise.</returns> |
| | | 34 | | public static bool TryCreateValidUri(string uriString, UriKind uriKind, out Uri result) |
| | | 35 | | { |
| | 0 | 36 | | return Uri.TryCreate(uriString, uriKind, out result); |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | } |