/// <summary> /// Constructs a map reads one or more values from one or more cells and maps these values as element /// contained by the property or field. /// </summary> /// <param name="member">The property or field to map the values of one or more cell to.</param> /// <param name="elementMapping">The map that maps the value of a single cell to an object of the element type of the property or field.</param> protected EnumerableExcelPropertyMap(MemberInfo member, SingleExcelPropertyMap <T> elementMapping) : base(member) { ElementMap = elementMapping ?? throw new ArgumentNullException(nameof(elementMapping)); var columnReader = new ColumnNameValueReader(member.Name); ColumnsReader = new SplitCellValueReader(columnReader); }
/// <summary> /// Sets the reader for multiple values to split the value of a single cell contained in the column /// with a given name. /// </summary> /// <param name="columnName">The name of the column containing the cell to split.</param> /// <returns>The property map that invoked this method.</returns> public EnumerableExcelPropertyMap <T> WithColumnName(string columnName) { var columnReader = new ColumnNameValueReader(columnName); if (ColumnsReader is SplitCellValueReader splitColumnReader) { splitColumnReader.CellReader = columnReader; } else { ColumnsReader = new SplitCellValueReader(columnReader); } return(this); }
/// <summary> /// Sets the reader for multiple values to split the value of a single cell contained in the column /// at the given zero-based index. /// </summary> /// <param name="columnIndex">The zero-bassed index of the column containing the cell to split.</param> /// <returns>The property map that invoked this method.</returns> public EnumerableExcelPropertyMap <T> WithColumnIndex(int columnIndex) { var reader = new ColumnIndexValueReader(columnIndex); if (ColumnsReader is SplitCellValueReader splitColumnReader) { splitColumnReader.CellReader = reader; } else { ColumnsReader = new SplitCellValueReader(reader); } return(this); }
public void CellValuesReader_SetValid_GetReturnsExpected(IMultipleCellValuesReader value) { var cellValuesReader = new MultipleColumnNamesValueReader("Column"); var elementPipeline = new ValuePipeline <string>(); CreateElementsFactory <string> createElementsFactory = elements => elements; var propertyMap = new ManyToOneEnumerableMap <string>(cellValuesReader, elementPipeline, createElementsFactory) { CellValuesReader = value }; Assert.Same(value, propertyMap.CellValuesReader); // Set same. propertyMap.CellValuesReader = value; Assert.Same(value, propertyMap.CellValuesReader); }
/// <summary> /// Sets the reader of the property map to read the values of one or more cells contained /// in the columns with the given zero-based indices. /// </summary> /// <param name="columnIndices">The zero-based index of each column to read.</param> /// <returns>The property map that invoked this method.</returns> public EnumerableExcelPropertyMap <T> WithColumnIndices(params int[] columnIndices) { ColumnsReader = new MultipleColumnIndicesValueReader(columnIndices); return(this); }
/// <summary> /// Constructs a map reads one or more values from one or more cells and maps these values as element /// contained by the property or field. /// </summary> /// <param name="valuePipeline">The map that maps the value of a single cell to an object of the element type of the property or field.</param> public ManyToOneDictionaryMap(IMultipleCellValuesReader cellValuesReader, IValuePipeline <T> valuePipeline, CreateDictionaryFactory <T> createDictionaryFactory) { CellValuesReader = cellValuesReader ?? throw new ArgumentNullException(nameof(cellValuesReader)); ValuePipeline = valuePipeline ?? throw new ArgumentNullException(nameof(valuePipeline)); CreateDictionaryFactory = createDictionaryFactory ?? throw new ArgumentNullException(nameof(createDictionaryFactory)); }