public static T ConvertTo <T>(this object value, CultureInfo cultureInfo, EConvertToOptions options, params object[] defaultValues) { bool isNullSeen = false; T result; if (InternalConvertTo(value, cultureInfo, out result)) { if ((result == null && !options.HasFlag(EConvertToOptions.AvoidNull)) || result != null) { return(result); } else if (result == null) { isNullSeen = true; } } foreach (var defaultValue in defaultValues) { if (InternalConvertTo(defaultValue, cultureInfo, out result)) { if ((result == null && !options.HasFlag(EConvertToOptions.AvoidNull)) || result != null) { return(result); } else if (result == null) { isNullSeen = true; } } } if (options.HasFlag(EConvertToOptions.NoException)) { return(default(T)); //return isNullSeen && options.HasFlag(EConvertToOptions.AvoidNull) ? (T)null as T : default(T); } else { throw new Exception("Could not convert to specified type."); } // return default(T); }