public static bool TryConvertOrCast <T>(object initialValue, CultureInfo culture, out T convertedValue)
 {
     return(MiscellaneousUtils.TryAction <T>(() => {
         object obj;
         ConvertUtils.TryConvertOrCast(initialValue, CultureInfo.CurrentCulture, typeof(T), out obj);
         return (T)obj;
     }, out convertedValue));
 }
Exemplo n.º 2
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));
        }
 public static bool TryConvert <T>(object initialValue, CultureInfo culture, out T convertedValue)
 {
     return(MiscellaneousUtils.TryAction <T>(delegate
     {
         object obj;
         ConvertUtils.TryConvert(initialValue, CultureInfo.get_CurrentCulture(), typeof(T), out obj);
         return (T)((object)obj);
     }, out convertedValue));
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
 public static bool TryGetSingleItem <T>(IList <T> list, bool returnDefaultIfEmpty, out T value)
 {
     return(MiscellaneousUtils.TryAction <T>(() => CollectionUtils.GetSingleItem <T>(list, returnDefaultIfEmpty), out value));
 }
Exemplo n.º 8
0
 public static bool TryConvert(object initialValue, CultureInfo culture, Type targetType, out object convertedValue)
 {
     return(MiscellaneousUtils.TryAction <object>((Creator <object>)(() => ConvertUtils.Convert(initialValue, culture, targetType)), out convertedValue));
 }