示例#1
0
        public CsvSerializerState Create(string assemblyName, string entityName, Stream toStream)
        {
            var delimiter = this.delimiterElector.Elect(toStream);

            toStream.Seek(0, SeekOrigin.Begin);

            var factory     = new SpreadsheetFactory(delimiter);
            var spreadsheet = factory.Create(toStream, 5);

            toStream.Seek(0, SeekOrigin.Begin);

            var delimitedHeader = this.delimitedHeaderElector.Elect(spreadsheet);

            var typeBuilder = new AnonymousEntityTypeBuilder();
            var typeColumns = delimitedHeader
                              .DelimitedColumns
                              .Select(x => new AnonymousEntityTypeProperty {
                Name = x.Name, Type = x.Type
            })
                              .ToArray();

            var entityType = typeBuilder.Create(assemblyName, entityName, typeColumns);

            var serializerType = typeof(CsvSerializer <>).MakeGenericType(entityType);

            return(CsvSerializerState.Create(
                       delimiter,
                       delimitedHeader.DelimitedColumns,
                       entityType,
                       Activator.CreateInstance(serializerType)));
        }
示例#2
0
        public void SpreadsheetShouldParseRequestedNumberOfRows()
        {
            var delimiter = new Delimiter {
                DelimitedBy = ','
            };

            var stream  = "1,2\r\n3,4\r\n4,5".ToStream();
            var factory = new SpreadsheetFactory(delimiter);

            var testSubject = factory.Create(stream, 1);

            testSubject.Rows.Should().Be(1);
            testSubject.Columns.Should().Be(2);
        }