Search Results for

    Show / Hide Table of Contents

    Class CsvParser<T>

    Fluent CSV Machine - an expressions based CSV parser

    Inheritance
    System.Object
    CsvParser<T>
    Namespace: FluentCsvMachine
    Assembly: library.dll
    Syntax
    public class CsvParser<T> : object where T : new()
    Type Parameters
    Name Description
    T

    Type of the entity which represents a CSV line

    Methods

    | Improve this Doc View Source

    LineAction(Action<T, IReadOnlyList<Nullable<Object>>>)

    Defines an action which runs after all properties (normal as well as custom ones) have been mapped

    Declaration
    public void LineAction(Action<T, IReadOnlyList<object?>> lineAction)
    Parameters
    Type Name Description
    Action<T, IReadOnlyList<System.Nullable<System.Object>>> lineAction

    Action(Entity, List of parsed csv fields) List is represents the CSV columns which have a column defined, others will be null The index matches the CSV columns The type of the object in the list is based on the columns you have defined These actions will be executed in the end of the entity creation Use this method only if PropertyCustom is not able to do what you want to achieve

    | Improve this Doc View Source

    Parse(String, CsvConfiguration)

    Parses the passed CSV File A header does need to exist in the CSV file Please setup your configuration with Property<V>(Expression<Func<T, Nullable<Object>>>) and PropertyCustom<V>(Action<T, V>),

    Declaration
    public Task<IReadOnlyList<T>> Parse(string path, CsvConfiguration config = null)
    Parameters
    Type Name Description
    System.String path

    Path to the CSV file

    CsvConfiguration config

    CsvConfiguration object, if not defined defaults are used

    Returns
    Type Description
    Task<IReadOnlyList<T>>

    List of parsed objects of type T

    | Improve this Doc View Source

    ParseStream(Stream, CsvConfiguration)

    Parses the passed CSV stream object A header does need to exist in the CSV file Please setup your configuration with Property<V>(Expression<Func<T, Nullable<Object>>>) and PropertyCustom<V>(Action<T, V>),

    Declaration
    public Task<IReadOnlyList<T>> ParseStream(Stream stream, CsvConfiguration config = null)
    Parameters
    Type Name Description
    Stream stream

    Stream of the CSV file

    CsvConfiguration config

    CsvConfiguration object, if not defined defaults are used

    Returns
    Type Description
    Task<IReadOnlyList<T>>

    List of parsed objects of type T

    | Improve this Doc View Source

    ParseWithoutHeader(Stream, CsvConfiguration)

    Parses the passed CSV stream which does not contain a header. Therefore you need setup your configuration with the CsvNoHeaderAttribute on the properties of T and set the index of the column directly. Not allowed is the use of Property<V>(Expression<Func<T, Nullable<Object>>>) and PropertyCustom<V>(Action<T, V>) because you cannot set the Property.ColumnName

    Declaration
    public Task<IReadOnlyList<T>> ParseWithoutHeader(Stream stream, CsvConfiguration config = null)
    Parameters
    Type Name Description
    Stream stream

    Stream of the CSV file

    CsvConfiguration config

    CsvConfiguration object, if not defined defaults are used

    Returns
    Type Description
    Task<IReadOnlyList<T>>

    List of parsed objects of type T

    | Improve this Doc View Source

    ParseWithoutHeader(String, CsvConfiguration)

    Parses the passed CSV file which does not contain a header Therefore you need setup your configuration with CsvNoHeaderAttribute and set the Index of the column directly Not allowed is the use of Property<V>(Expression<Func<T, Nullable<Object>>>) and PropertyCustom<V>(Action<T, V>) because you cannot set the Property.ColumnName

    Declaration
    public Task<IReadOnlyList<T>> ParseWithoutHeader(string path, CsvConfiguration config = null)
    Parameters
    Type Name Description
    System.String path

    Path to the CSV file

    CsvConfiguration config

    CsvConfiguration object, if not defined defaults are used

    Returns
    Type Description
    Task<IReadOnlyList<T>>

    List of parsed objects of type T

    | Improve this Doc View Source

    Property<V>(Expression<Func<T, Nullable<Object>>>)

    Defines a Column / Property

    Declaration
    public CsvProperty<T> Property<V>(Expression<Func<T, object?>> accessor)
    Parameters
    Type Name Description
    Expression<Func<T, System.Nullable<System.Object>>> accessor
    Returns
    Type Description
    CsvProperty<T>

    Property for the fluent interface

    Type Parameters
    Name Description
    V

    value type

    | Improve this Doc View Source

    PropertyCustom<V>(Action<T, V>)

    Defines a custom mapping based on a type Will be executed after all normal Properties Can assign modify multiple properties of the entity if you want to do that Input is always the parsed value of the CSV column in the type V

    Declaration
    public CsvPropertyCustom<T, V> PropertyCustom<V>(Action<T, V> customAction)
    Parameters
    Type Name Description
    Action<T, V> customAction

    Action(Entity for value assignment, parsed csv value)

    Returns
    Type Description
    CsvPropertyCustom<T, V>

    Property for the fluent interface

    Type Parameters
    Name Description
    V
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright travelr - MIT License