本文整理汇总了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 );
}
示例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] );
}
示例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 ) );
}
示例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 );
}
示例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 );
}
}
示例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 )
{
}
}
示例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 )
{
}
}
示例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 );
}
示例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 );
}