CSV Reports
CsvStreamToObjectList<T> Method
Example 



KellermanSoftware.CsvReports Namespace > CsvReader Class : CsvStreamToObjectList<T> Method
Read a CSV stream into a list of objects. Public properties are mapped by name, they are case sensitive. By default header column name spaces are removed. See RemoveColumnNameSpaces. It will automatically map all primitive types such as int, long, string and complex types of GUID, Enum, DateTime Properties that do not exist are ignored.
Syntax
Public Function CsvStreamToObjectList(Of T As {Class, New})( _
   ByVal stream As Stream _
) As List(Of T)
Dim instance As CsvReader
Dim stream As Stream
Dim value As List(Of T)
 
value = instance.CsvStreamToObjectList(Of T)(stream)
public List<T> CsvStreamToObjectList<T>( 
   Stream stream
)
where T: class, new()
public:
List<T^>^ CsvStreamToObjectListgeneric<typename T>
( 
   Stream^ stream
) 
where T: ref class, gcnew()

Parameters

stream

Type Parameters

T
Example
//Example Mapping Class
public class TestMapper
{
    public string Name { get; set; }
    public string Birthdate { get; set; }
}
 
CsvReader csvReader = new CsvReader(); //Trial Mode
//CsvReader csvReader = new CsvReader("place user name here", "place license key here"); //License Mode
 
//Create a test file
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testReader.csv");
File.WriteAllText(filePath, "Name,Birthdate\r\nJohn,5/30/2013");
 
List<TestMapper> results;
 
using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
    results = csvReader.CsvStreamToObjectList<TestMapper>(stream);
}
 
Console.WriteLine(results[0].Name);
'Example Mapping Class
Public Class TestMapper
    Public Property Name() As String
    Public Property Birthdate() As String
End Class
 
Dim csvReader As New CsvReader() 'Trial Mode
'Dim csvReader As New CsvReader("place user name here", "place license key here") 'License Mode
 
'Create a test file
Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testReader.csv")
File.WriteAllText(filePath, "Name,Birthdate" & vbCrLf & "John,5/30/2013")
 
Dim results As List(Of TestMapper)
 
Using stream As New FileStream(filePath, FileMode.Open, FileAccess.Read)
    results = csvReader.CsvStreamToObjectList(Of TestMapper)(stream)
End Using
 
Console.WriteLine(results(0).Name)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CsvReader Class
CsvReader Members