Esempio n. 1
0
        /// <summary>
        /// Determines whether the specified value is a protocol-relative URI string.
        /// </summary>
        /// <param name="value">The string value representing the protocol-relative URI.</param>
        /// <param name="relativeReference">The relative reference that <paramref name="value"/> must begin with. Default is <see cref="StringUtility.NetworkPathReference"/>.</param>
        /// <returns><c>true</c> if the specified <paramref name="value"/> is a protocol-relative URI; otherwise, <c>false</c>.</returns>
        public static bool IsProtocolRelativeUri(string value, string relativeReference)
        {
            Validator.ThrowIfNullOrEmpty(value, nameof(value));
            Validator.ThrowIfNullOrEmpty(relativeReference, nameof(relativeReference));
            Uri ignoreUri;

            return(TesterFuncUtility.TryExecuteFunction(() => UriConverter.FromProtocolRelativeUri(value, UriScheme.Https, relativeReference), out ignoreUri));
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to convert the specified <paramref name="value"/> to a given type. If the conversion is not possible the result is set to <paramref name="resultOnConversionNotPossible"/>.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="value">The object to convert the underlying type.</param>
        /// <param name="resultOnConversionNotPossible">The value to return if the conversion is not possible.</param>
        /// <param name="provider">An object that supplies culture-specific formatting information.</param>
        /// <returns>The <paramref name="value"/> converted to the specified <typeparamref name="TResult"/>.</returns>
        /// <remarks>This method first checks if <paramref name="value"/> is compatible with <typeparamref name="TResult"/>; if not compatible the method continues with <see cref="ObjectConverter.ChangeType(object,System.Type,IFormatProvider)"/> for the operation.</remarks>
        public static TResult FromObject <TResult>(object value, TResult resultOnConversionNotPossible, IFormatProvider provider)
        {
            if (value is TResult)
            {
                return((TResult)value);
            }
            object o;
            bool   success = TesterFuncUtility.TryExecuteFunction(ObjectConverter.ChangeType, value, typeof(TResult), provider, out o);

            return(success ? (TResult)o : resultOnConversionNotPossible);
        }
Esempio n. 3
0
 /// <summary>
 /// Converts the specified <paramref name="value"/> of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.
 /// A parameter specifies whether the operation is case-sensitive. The return value indicates whether the conversion succeeded.
 /// </summary>
 /// <typeparam name="TEnum">The type of the enumeration to convert.</typeparam>
 /// <param name="value">A string containing the name or value to convert.</param>
 /// <param name="ignoreCase"><c>true</c> to ignore case; <c>false</c> to regard case.</param>
 /// <param name="result">When this method returns, <paramref name="result"/> contains an object of type <typeparamref name="TEnum"/> whose value is represented by <paramref name="value"/> if the parse operation succeeds. If the parse operation fails, result contains the default value of the underlying type of <typeparamref name="TEnum"/>.</param>
 /// <returns><c>true</c> if the <paramref name="value"/> parameter was converted successfully; otherwise, <c>false</c>.</returns>
 public static bool TryParse <TEnum>(string value, bool ignoreCase, out TEnum result) where TEnum : struct, IConvertible
 {
     return(TesterFuncUtility.TryExecuteFunction(Parse <TEnum>, value, ignoreCase, out result));
 }
Esempio n. 4
0
 /// <summary>
 /// Converts the specified string representation of an URI value to its <see cref="Uri"/> equivalent, limited to what is specified in the <see paramref="schemes"/> parameter.
 /// </summary>
 /// <param name="uriString">A string containing the URI to convert.</param>
 /// <param name="uriKind">The type of the URI.</param>
 /// <param name="uriSchemes">A sequence of <see cref="UriScheme"/> values to use in the parsing of the URI.</param>
 /// <param name="result">When this method returns, contains the constructed <see cref="Uri"/>.</param>
 /// <returns>
 ///     <c>true</c> if the <see cref="Uri"/> was successfully created; otherwise, false.
 /// </returns>
 /// <remarks>
 /// If this method returns true, the new <see cref="Uri"/> is in result.
 /// </remarks>
 public static bool TryParse(string uriString, UriKind uriKind, IEnumerable <UriScheme> uriSchemes, out Uri result)
 {
     return(TesterFuncUtility.TryExecuteFunction(Parse, uriString, uriKind, uriSchemes, out result));
 }