Beispiel #1
0
        /// <summary>
        /// Converts the value to the specified type. If the value is unable to be converted, the
        /// value is checked whether it assignable to the specified type.
        /// </summary>
        /// <typeparam name="T">The type to convert the value to.</typeparam>
        /// <param name="initialValue">The value to convert.</param>
        /// <param name="culture">The culture to use when converting.</param>
        /// <param name="convertedValue">The converted value if the conversion was successful or the default value of <c>T</c> if it failed.</param>
        /// <returns>
        ///     <c>true</c> if <c>initialValue</c> was converted successfully or is assignable; otherwise, <c>false</c>.
        /// </returns>
        public static bool TryConvertOrCast <T>(object initialValue, CultureInfo culture, out T convertedValue)
        {
            return(MiscellaneousUtils.TryAction <T>(delegate
            {
                object tempConvertedValue;
                TryConvertOrCast(initialValue, CultureInfo.CurrentCulture, typeof(T), out tempConvertedValue);

                return (T)tempConvertedValue;
            }, out convertedValue));
        }
Beispiel #2
0
        public static bool TryParse <T>(string enumMemberName, bool ignoreCase, out T value) where T : struct
        {
            ValidationUtils.ArgumentTypeIsEnum(typeof(T), "T");

            return(MiscellaneousUtils.TryAction(() => Parse <T>(enumMemberName, ignoreCase), out value));
        }
Beispiel #3
0
 /// <summary>
 /// Converts the value to the specified type. If the value is unable to be converted, the
 /// value is checked whether it assignable to the specified type.
 /// </summary>
 /// <param name="initialValue">The value to convert.</param>
 /// <param name="culture">The culture to use when converting.</param>
 /// <param name="targetType">The type to convert the value to.</param>
 /// <param name="convertedValue">The converted value if the conversion was successful or the default value of <c>T</c> if it failed.</param>
 /// <returns>
 ///     <c>true</c> if <c>initialValue</c> was converted successfully or is assignable; otherwise, <c>false</c>.
 /// </returns>
 public static bool TryConvertOrCast(object initialValue, CultureInfo culture, Type targetType, out object convertedValue)
 {
     return(MiscellaneousUtils.TryAction <object>(delegate { return ConvertOrCast(initialValue, culture, targetType); }, out convertedValue));
 }
Beispiel #4
0
 public static bool TryGetSingleItem <T>(IList <T> list, bool returnDefaultIfEmpty, out T value)
 {
     return(MiscellaneousUtils.TryAction <T>(delegate { return GetSingleItem(list, returnDefaultIfEmpty); }, out value));
 }