本文整理汇总了C#中CsvReader.ElementAtOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ElementAtOrDefault方法的具体用法?C# CsvReader.ElementAtOrDefault怎么用?C# CsvReader.ElementAtOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.ElementAtOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadSchema
/// <summary>
/// Loads the database for this instance.
/// may be called multiple times, if uploading multiple CSV files.
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public override bool LoadSchema( string fileName )
{
//enforce that the filename must be a known configuration.
if ( !FileIsKnown( fileName ) )
return false;
var dbPreview = new CsvReader( new StreamReader( fileName ), true );
if ( CsvDataToImport == null )
{
CsvDataToImport = new List<CsvDataModel>();
TableNodes = new List<DatabaseNode>();
}
//a local tableNode object, which will track this one of multiple CSV files that may be imported
List<DatabaseNode> tableNodes = new List<DatabaseNode>();
CsvDataToImport.Add( new CsvDataModel( fileName ) { TableNodes = tableNodes, RecordType = GetRecordTypeFromFilename( fileName ) } );
var tableItem = new DatabaseNode();
tableItem.Name = Path.GetFileNameWithoutExtension( fileName );
int currentIndex = 0;
var firstRow = dbPreview.ElementAtOrDefault( 0 );
if ( firstRow != null )
{
foreach ( var columnName in dbPreview.GetFieldHeaders() )
{
var childItem = new DatabaseNode();
childItem.Name = columnName;
childItem.NodeType = typeof( string );
childItem.Value = firstRow[currentIndex] ?? string.Empty;
childItem.Table.Add( tableItem );
tableItem.Columns.Add( childItem );
currentIndex++;
}
tableNodes.Add( tableItem );
TableNodes.Add( tableItem ); //this is to maintain compatibility with the base Excavator object.
}
return tableNodes.Count() > 0 ? true : false;
}