/// <summary>
        /// Read from data
        /// </summary>
        /// <param name="table"></param>
        public void Load(DataTable table)
        {
            Expect.IsNotNull(table, nameof(table));
            _columns.Clear();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                var row    = table.Rows[i];
                var column = new SchemaMappingColumn();
                column.Load(row);
                AddColumn(column);
            }
        }
        /// <summary>
        /// Get field mapper if mapping exist, or map to generic property if not mapped
        /// </summary>
        /// <param name="column"></param>
        /// <returns></returns>
        internal IFieldReader <T> GetFieldReader(SchemaMappingColumn column)
        {
            Expect.IsNotNull(column, nameof(column));

            var fieldMapper = FieldMappers.FirstOrDefault(x => x.Match(column));

            if (fieldMapper != null)
            {
                return(fieldMapper);
            }
            else
            {
                return(new GenericFieldReader <T>(column.ColumnName, column.ClrType));
            }
        }
        /// <inheritdoc />
        public bool Match(SchemaMappingColumn column)
        {
            if (!FieldName.EqualsNoCase(column.ColumnName))
            {
                return(false);
            }

            var columnType = column.ClrType;

            if (PropertyType.IsNullableType() && columnType.IsNullableType())
            {
                if (MatchType(PropertyType.GetNullableBaseType(), columnType.GetNullableBaseType()))
                {
                    return(true);
                }
            }

            return(MatchType(PropertyType, columnType));
        }
        /// <summary>
        /// Add column
        /// </summary>
        /// <param name="column"></param>
        public void AddColumn(SchemaMappingColumn column)
        {
            Expect.IsNotNull(column, nameof(column));

            _columns.Add(column);
        }
Exemple #5
0
 /// <inheritdoc />
 public bool Match(SchemaMappingColumn column)
 {
     return(true);
 }