Class CsvStorage<T>
This class provides access to CSV files (charcater separated values) and parses the data into the application-side type T.
Inheritance
Namespace: TeleScope.Persistence.Csv
Assembly: TeleScope.Persistence.Csv.dll
Syntax
public class CsvStorage<T> : object, IReadable<T>, IFileWritable<T>, IWritable<T>
Type Parameters
Name | Description |
---|---|
T | The type T is used application-side and can be read from the data source or be written to the data sink. |
Constructors
| Improve this Doc View SourceCsvStorage(String)
The constructor takes the file string as input parameter, creates the CsvStorageSetup and allows to config the properties afterwards.
Declaration
public CsvStorage(string file)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | The specific CSV file that the storage is related to. |
CsvStorage(CsvStorageSetup)
The constructor takes the setup of type CsvStorageSetup as input parameter and binds the logging mechanism.
Declaration
public CsvStorage(CsvStorageSetup csvSetup)
Parameters
Type | Name | Description |
---|---|---|
CsvStorageSetup | csvSetup | The setup is needed to work with a specific CSV file. |
Properties
| Improve this Doc View SourceOnItemRead
The delegate handles the read operation of a CSV line and returned the targeted internal type.
Declaration
public PersistenceHandler<string[], T> OnItemRead { set; }
Property Value
Type | Description |
---|---|
PersistenceHandler<System.String[], T> |
OnItemWrite
The delegate handles the write operation to a CSV to a string array that represents a line. The input data is the internal type of the storage.
Declaration
public PersistenceHandler<T, string[]> OnItemWrite { set; }
Property Value
Type | Description |
---|---|
PersistenceHandler<T, System.String[]> |
Permissions
Gets the flags of permissions how files may be treated.
Declaration
public WritePermissions Permissions { get; }
Property Value
Type | Description |
---|---|
WritePermissions |
Methods
| Improve this Doc View SourceHasPermission(WritePermissions)
Checks if the permission is a present flag or not.
Declaration
public bool HasPermission(WritePermissions permission)
Parameters
Type | Name | Description |
---|---|---|
WritePermissions | permission | The enum that is checked. |
Returns
Type | Description |
---|---|
System.Boolean | True if the value is a present flag, otherwise false. |
Read()
Reads a given CSV file as data source and provides a collection of type T. If there is only one data object a collection with the length one is returned.
Declaration
public IEnumerable<T> Read()
Returns
Type | Description |
---|---|
IEnumerable<T> | The resulting data objects of type T. |
Update(FileInfo)
Updates the reference to the internal
Declaration
public IFileWritable<T> Update(FileInfo fileInfo)
Parameters
Type | Name | Description |
---|---|---|
FileInfo | fileInfo | The new FileInfo object. |
Returns
Type | Description |
---|---|
IFileWritable<T> | The calling instance. |
Update(String)
Updates the reference to the internal
Declaration
public IFileWritable<T> Update(string file)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | The new string of the file. |
Returns
Type | Description |
---|---|
IFileWritable<T> | The calling instance. |
Write(IEnumerable<T>)
Writes a collection of type T to a CSV file as data sink. If there is only one data object there is the need to provide a collection with one element.
Declaration
public void Write(IEnumerable<T> data)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | data | The application-side data collection of type T. |