Beispiel #1
0
        private void processData <T>(TextReader reader, CsvData headers, CsvRequest <T> request)
        {
            var mapping = request.Mapping.As <IColumnMapping>();

            readUntilComplete(reader, tokens =>
            {
                var source = valueSourceFor(tokens, headers, mapping);
                var result = _resolver.BindModel(typeof(T), source);

                request.Callback(result.Value.As <T>());
                return(true);
            });
        }
Beispiel #2
0
        public void Read <T>(CsvRequest <T> request)
        {
            using (var stream = request.OpenStream())
            {
                using (var reader = new StreamReader(stream))
                {
                    _tokenizer.DelimitBy(request.Delimiter);

                    var headers = determineHeaders(reader, request);
                    processData(reader, headers, request);
                }
            }
        }
Beispiel #3
0
        private CsvData determineHeaders <T>(TextReader reader, CsvRequest <T> request)
        {
            CsvData headers = null;

            if (request.HeadersExist)
            {
                readUntilComplete(reader, tokens =>
                {
                    if (tokens.Any() && request.UseHeaderOrdering)
                    {
                        headers = new CsvData(tokens);
                    }
                    return(false);
                });
            }

            return(headers);
        }