private FixedLengthSchemaSelector getSchemaSelector()
        {
            var selector = new FixedLengthSchemaSelector();

            selector.When(values => values.Length == 28).Use(getHeaderSchema());
            selector.When(values => values.Length == 25).Use(getFooterSchema());
            selector.WithDefault(getRecordSchema());
            return(selector);
        }
Beispiel #2
0
        /// <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 IFixedLengthTypedReader <object> GetReader(TextReader reader, FixedLengthOptions options = null)
        {
            var selector    = new FixedLengthSchemaSelector();
            var valueReader = new FixedLengthReader(reader, selector, options);
            var multiReader = new MultiplexingFixedLengthTypedReader(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);
        }