/// <summary> /// Obtenir/Convertir en INT Nullable /// </summary> /// <param name="dataAccessor"></param> /// <param name="nameValue"></param> /// <param name="AccesOptions"></param> /// <param name="defaultvalue"></param> /// <returns></returns> public static int?GetInt(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions, int?defaultvalue) { try { object obj = dataAccessor.GetObject(nameValue, AccesOptions); if (obj == DBNull.Value || obj == null) { return(null); } else if (AccesOptions.HasFlag(DataAccessorOptionEnum.AdvancedConverter)) { return(ConvertPlus.ToInt(obj)); } else { return(Convert.ToInt32(obj)); } } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("GetString " + ex.Message, ex); } throw; } }
/// <summary> /// Obtenir/Convertir en INT /// </summary> /// <param name="dataAccessor"></param> /// <param name="nameValue"></param> /// <param name="DefaultValue"></param> /// <param name="AccesOptions"></param> /// <returns></returns> public static int GetInt(this IDataAccessor dataAccessor, string nameValue, int DefaultValue, DataAccessorOptionEnum AccesOptions = 0) { try { object obj = dataAccessor.GetObject(nameValue, AccesOptions); if (obj == DBNull.Value || obj == null) { return(DefaultValue); } if (obj is string && string.IsNullOrWhiteSpace((string)obj)) { return(DefaultValue); } else if (AccesOptions.HasFlag(DataAccessorOptionEnum.AdvancedConverter)) { return(ConvertPlus.ToInt(obj, DefaultValue)); } else { return(Convert.ToInt32(obj)); } } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("GetString " + ex.Message, ex); } throw; } }