Information Technology Reference
In-Depth Information
return result != null ;
}
}
private List < string > columnNames = new List < string >();
private List < CSVRow > data = new List < CSVRow >();
public CSVDataContainer(System.IO. TextReader stream)
{
// read headers:
var headers = stream.ReadLine();
columnNames =
( from header in headers.Split( ',' )
select header.Trim()).ToList();
var line = stream.ReadLine();
while (line != null )
{
var items = line.Split( ',' );
data.Add( new CSVRow (columnNames, items));
line = stream.ReadLine();
}
}
public dynamic this [ int index]
{
get { return data[index]; }
}
public IEnumerable < dynamic > Rows
{
get { return data; }
}
}
Even though you need to expose a dynamic type as part of your interface,
it's only where the dynamicism is needed. Those APIs are dynamic. They
must be. You can't support any possible CSV format without having
dynamic support for column names. You could have chosen to expose
everything using dynamic. Instead, dynamic appears in the interface only
where the functionality demands dynamic.
For space purposes, I elided other features in the CSVDataContainer.
Think about how you would implement RowCount, ColumnCount,
Search WWH ::




Custom Search