Example #1
0
        /// <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);
        }