//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------- namespace System.IdentityModel { using System; internal static class UriUtil { /// /// Determines whether a URI is valid and can be created using the specified UriKind. /// Uri.TryCreate is used here, which is more lax than Uri.IsWellFormedUriString. /// The reason we use this function is because IsWellFormedUriString will reject valid URIs if they are IPv6 or require escaping. /// /// The string to check. /// The type of URI (usually UriKind.Absolute) /// True if the URI is valid, false otherwise. public static bool CanCreateValidUri(string uriString, UriKind uriKind) { Uri tempUri; return TryCreateValidUri(uriString, uriKind, out tempUri); } /// /// Determines whether a URI is valid and can be created using the specified UriKind. /// Uri.TryCreate is used here, which is more lax than Uri.IsWellFormedUriString. /// The reason we use this function is because IsWellFormedUriString will reject valid URIs if they are IPv6 or require escaping. /// /// The string to check. /// The type of URI (usually UriKind.Absolute) /// An out param representing the created URI /// True if the URI is valid, false otherwise. public static bool TryCreateValidUri(string uriString, UriKind uriKind, out Uri result) { return Uri.TryCreate(uriString, uriKind, out result); } } }