private static void AddFormats(this IValuePipeline propertyMap, string[] formats) { if (formats == null) { throw new ArgumentNullException(nameof(formats)); } if (formats.Length == 0) { throw new ArgumentException("Formats cannot be empty.", nameof(formats)); } DateTimeMapper dateTimeItem = (DateTimeMapper)propertyMap.CellValueMappers.FirstOrDefault(item => item is DateTimeMapper); if (dateTimeItem == null) { dateTimeItem = new DateTimeMapper(); propertyMap.AddCellValueMapper(dateTimeItem); } dateTimeItem.Formats = formats; }
internal static object GetPropertyValue(IValuePipeline pipeline, ExcelSheet sheet, int rowIndex, IExcelDataReader reader, ReadCellValueResult readResult, MemberInfo member) { foreach (ICellValueTransformer transformer in pipeline.CellValueTransformers) { readResult = new ReadCellValueResult(readResult.ColumnIndex, transformer.TransformStringValue(sheet, rowIndex, readResult)); } if (string.IsNullOrEmpty(readResult.StringValue) && pipeline.EmptyFallback != null) { return(pipeline.EmptyFallback.PerformFallback(sheet, rowIndex, readResult, member)); } PropertyMapperResultType resultType = PropertyMapperResultType.Success; object value = null; foreach (ICellValueMapper mappingItem in pipeline.CellValueMappers) { PropertyMapperResultType newResultType = mappingItem.MapCellValue(readResult, ref value); if (newResultType == PropertyMapperResultType.Success) { return(value); } if (newResultType != PropertyMapperResultType.Continue) { resultType = newResultType; } } if (resultType != PropertyMapperResultType.Success && resultType != PropertyMapperResultType.SuccessIfNoOtherSuccess && pipeline.InvalidFallback != null) { return(pipeline.InvalidFallback.PerformFallback(sheet, rowIndex, readResult, member)); } return(value); }
/// <summary> /// Specifies data formats used when mapping the value of a cell to a DateTime. This is useful for /// mapping columns where data formats differ. Existing date formats are overriden. /// </summary> /// <param name="propertyMap">The property map to use.</param> /// <param name="formats">A list of date formats to use when mapping the value of a cell to a DateTime.</param> /// <returns>The property map on which this method was invoked.</returns> public static IValuePipeline <DateTime> WithDateFormats(this IValuePipeline <DateTime> propertyMap, IEnumerable <string> formats) { return(propertyMap.WithDateFormats(formats?.ToArray())); }
/// <summary> /// Specifies data formats used when mapping the value of a cell to a DateTime. This is useful for /// mapping columns where data formats differ. Existing date formats are overriden. /// </summary> /// <param name="propertyMap">The property map to use.</param> /// <param name="formats">A list of date formats to use when mapping the value of a cell to a DateTime.</param> /// <returns>The property map on which this method was invoked.</returns> public static IValuePipeline <DateTime> WithDateFormats(this IValuePipeline <DateTime> propertyMap, params string[] formats) { propertyMap.AddFormats(formats); return(propertyMap); }
public MemberAssigmentApplier(IValuePipeline pipeline) { this.pipeline = pipeline; }
protected ValuePipeline(IValuePipeline pipeline) { this.pipeline = pipeline; }
public OmniGuiValuePipeline(IValuePipeline inner) : base(inner) { }
public MarkupExtensionValuePipeline(IValuePipeline inner) : base(inner) { }
public TemplatePipeline(IValuePipeline pipeline, IMetadataProvider metadataProvider) : base(pipeline) { this.metadataProvider = metadataProvider; }
/// <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)); }