/// <summary> /// Creates the new item. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source">The source.</param> /// <param name="rowIndex">Index of the row.</param> /// <returns></returns> private static T CreateNewItem <T>(DBDataSource source, int rowIndex) where T : class, new() { var sourceFields = source.Fields; var columnCount = sourceFields.Count; var item = new T(); var type = typeof(T); for (var column = 0; column < columnCount; column++) { var columnName = sourceFields.Item(column).Name; var property = DetermineProperty(type, columnName); if (property.PropertyType == typeof(string)) { property.SetValue(item, source.GetString(columnName, rowIndex)); } if (property.PropertyType == typeof(int)) { property.SetValue(item, source.GetInt(columnName, rowIndex)); } if (property.PropertyType == typeof(double)) { property.SetValue(item, source.GetDouble(columnName, rowIndex)); } if (property.PropertyType == typeof(DateTime)) { property.SetValue(item, source.GetDateTime(columnName, rowIndex)); } } return(item); }
/// <summary> /// Gets the date time. /// </summary> /// <param name="source">The source.</param> /// <param name="columnId">The column identifier.</param> /// <param name="rowIndex">Index of the row.</param> /// <returns></returns> public static DateTime?GetDateTime(this DBDataSource source, string columnId, int rowIndex) { var sourceValue = source.GetString(columnId, rowIndex); if (string.IsNullOrEmpty(sourceValue)) { return(null); } var value = DateTime.ParseExact(sourceValue, "yyyyMMdd", CultureInfo.InvariantCulture); return(value); }
/// <summary> /// Gets the int. /// </summary> /// <param name="source">The source.</param> /// <param name="columnId">The column identifier.</param> /// <param name="rowIndex">Index of the row.</param> /// <returns></returns> public static int?GetInt(this DBDataSource source, string columnId, int rowIndex) { string sourceValue = source.GetString(columnId, rowIndex); if (string.IsNullOrEmpty(sourceValue)) { return(null); } var value = int.Parse(sourceValue, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); return(value); }