private SeparatedValueSchemaSelector getSchemaSelector() { var selector = new SeparatedValueSchemaSelector(); selector.When(values => values.Length == 2).Use(getHeaderSchema()); selector.When(values => values.Length == 3).Use(getFooterSchema()); selector.WithDefault(getRecordSchema()); return(selector); }
/// <summary> /// Gets a typed reader for reading the objects from the file. /// </summary> /// <param name="reader">The reader to use.</param> /// <param name="options">The separate value options to use.</param> /// <returns>The typed reader.</returns> public ISeparatedValueTypedReader <object> GetReader(TextReader reader, SeparatedValueOptions options = null) { var selector = new SeparatedValueSchemaSelector(); var valueReader = new SeparatedValueReader(reader, selector, options); var multiReader = new MultiplexingSeparatedValueTypedReader(valueReader); foreach (var matcher in matchers) { var typedReader = new Lazy <Func <IRecordContext, object[], object> >(GetReader(matcher.TypeMapper)); selector.When(matcher.Predicate).Use(matcher.TypeMapper.GetSchema()).OnMatch(() => multiReader.Deserializer = typedReader.Value); } if (defaultMapper != null) { var typeReader = new Lazy <Func <IRecordContext, object[], object> >(GetReader(defaultMapper)); selector.WithDefault(defaultMapper.GetSchema()).OnMatch(() => multiReader.Deserializer = typeReader.Value); } return(multiReader); }