当前位置: 首页>>代码示例>>C#>>正文


C# CsvReader.ReadHeader方法代码示例

本文整理汇总了C#中CsvReader.ReadHeader方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ReadHeader方法的具体用法?C# CsvReader.ReadHeader怎么用?C# CsvReader.ReadHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvReader的用法示例。


在下文中一共展示了CsvReader.ReadHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadHeaderDoesNotReadRowTest

        public void ReadHeaderDoesNotReadRowTest()
        {
            var rows = new Queue<string[]>();
            rows.Enqueue( new[] { "Id", "Name" } );
            rows.Enqueue( new[] { "1", "One" } );
            rows.Enqueue( new[] { "2", "two" } );
            rows.Enqueue( null );
            var parser = new ParserMock( rows );

            var csv = new CsvReader( parser );
            csv.Read();
            csv.ReadHeader();

            Assert.IsNull( csv.CurrentRecord );
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:15,代码来源:ReadHeaderTests.cs

示例2: ReadHeaderReadsHeaderTest

        public void ReadHeaderReadsHeaderTest()
        {
            var rows = new Queue<string[]>();
            rows.Enqueue( new[] { "Id", "Name" } );
            rows.Enqueue( new[] { "1", "One" } );
            rows.Enqueue( new[] { "2", "two" } );
            rows.Enqueue( null );
            var parser = new ParserMock( rows );

            var csv = new CsvReader( parser );
            csv.Read();
            csv.ReadHeader();

            Assert.IsNotNull( csv.FieldHeaders );
            Assert.AreEqual( "Id", csv.FieldHeaders[0] );
            Assert.AreEqual( "Name", csv.FieldHeaders[1] );
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:17,代码来源:ReadHeaderTests.cs

示例3: SkipEmptyRowTest

        public void SkipEmptyRowTest()
        {
            var rows = new Queue<string[]>();
            rows.Enqueue( new[] { "First,Second" } );
            rows.Enqueue( new[] { " " } );
            rows.Enqueue( new[] { "1", "2" } );
            var parser = new ParserMock( rows );

            var csv = new CsvReader( parser );
            csv.Configuration.ShouldSkipRecord = row => row.All( string.IsNullOrWhiteSpace );

            csv.Read();
            csv.ReadHeader();
            csv.Read();
            Assert.AreEqual( "1", csv.GetField( 0 ) );
            Assert.AreEqual( "2", csv.GetField( 1 ) );
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:17,代码来源:ShouldSkipRecordTests.cs

示例4: TryGetFieldIndexTest

        public void TryGetFieldIndexTest()
        {
            var parserMock = new ParserMock
            {
                { "One", "Two", "Two" },
                { "1", "2", "3" }
            };
            var reader = new CsvReader( parserMock );
            reader.Read();
            reader.ReadHeader();
            reader.Read();

            int field;
            var got = reader.TryGetField( "Two", 0, out field );
            Assert.IsTrue( got );
            Assert.AreEqual( 2, field );

            got = reader.TryGetField( "Two", 1, out field );
            Assert.IsTrue( got );
            Assert.AreEqual( 3, field );
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:21,代码来源:TryGetTests.cs

示例5: GetFieldIndexTest

        public void GetFieldIndexTest()
        {
            var parser = new ParserMock
            {
                { "Id", "Name" },
                { "a", "b" },
                null
            };

            var reader = new CsvReader( parser );
            reader.Read();
            reader.ReadHeader();
            reader.Read();
            try
            {
                reader.GetField( "c" );
                Assert.Fail();
            }
            catch( CsvMissingFieldException ex )
            {
                Assert.AreEqual( 2, ex.Row );
                Assert.AreEqual( -1, ex.FieldIndex );
            }
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:24,代码来源:ExceptionMessageTests.cs

示例6: ReadingHeaderFailsWhenHeaderAlreadyReadTest

        public void ReadingHeaderFailsWhenHeaderAlreadyReadTest()
        {
            var rows = new Queue<string[]>();
            rows.Enqueue( new[] { "Id", "Name" } );
            rows.Enqueue( new[] { "1", "One" } );
            rows.Enqueue( new[] { "2", "two" } );
            rows.Enqueue( null );
            var parser = new ParserMock( rows );

            var csv = new CsvReader( parser );
            csv.Read();
            csv.ReadHeader();

            try
            {
                csv.ReadHeader();
                Assert.Fail();
            }
            catch( CsvReaderException )
            {
            }
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:22,代码来源:ReadHeaderTests.cs

示例7: ReadingHeaderFailsWhenReaderIsDoneTest

        public void ReadingHeaderFailsWhenReaderIsDoneTest()
        {
            var rows = new Queue<string[]>();
            rows.Enqueue( new[] { "Id", "Name" } );
            rows.Enqueue( new[] { "1", "One" } );
            rows.Enqueue( new[] { "2", "two" } );
            rows.Enqueue( null );
            var parser = new ParserMock( rows );

            var csv = new CsvReader( parser );
            csv.Configuration.HasHeaderRecord = false;
            while( csv.Read() ) { }

            try
            {
                csv.ReadHeader();
                Assert.Fail();
            }
            catch( CsvReaderException )
            {
            }
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:22,代码来源:ReadHeaderTests.cs

示例8: TryGetFieldTest

        public void TryGetFieldTest()
        {
            var data1 = new[] { "One", "Two" };
            var data2 = new[] { "1", "2" };
            var queue = new Queue<string[]>();
            queue.Enqueue( data1 );
            queue.Enqueue( data2 );
            queue.Enqueue( null );
            var parserMock = new ParserMock( queue );

            var reader = new CsvReader( parserMock );
            reader.Read();
            reader.ReadHeader();
            reader.Read();

            int field;
            var got = reader.TryGetField( 0, out field );
            Assert.IsTrue( got );
            Assert.AreEqual( 1, field );
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:20,代码来源:TryGetTests.cs

示例9: TryGetFieldStrictTest

        public void TryGetFieldStrictTest()
        {
            var data1 = new[] { "One", "Two" };
            var data2 = new[] { "1", "2" };
            var queue = new Queue<string[]>();
            queue.Enqueue( data1 );
            queue.Enqueue( data2 );
            queue.Enqueue( null );
            var parserMock = new ParserMock( queue );

            var reader = new CsvReader( parserMock ) { Configuration = { WillThrowOnMissingField = true } };
            reader.Read();
            reader.ReadHeader();
            reader.Read();

            int field;
            var got = reader.TryGetField( "One", out field );
            Assert.IsTrue( got );
            Assert.AreEqual( 1, field );
        }
开发者ID:ravensorb,项目名称:CsvHelper,代码行数:20,代码来源:TryGetTests.cs


注:本文中的CsvReader.ReadHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。