Cinchoo / ChoETL

ETL framework for .NET (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
MIT License
746 stars 134 forks source link

ChoTypeConverter not firing #286

Closed JimF42 closed 1 year ago

JimF42 commented 1 year ago

Enclosed is a sample project where I need to read in an IPAddress from a CSV and put it into a IPAddress data type. I added a IChoValueConverter class and decorated the property with ChoTypeConverter(typeof(IpAddressTypeConverter)). It doesn't appear to be called (I added Console.WriteLine and System.Diagnostics.Debug.WriteLine statements, and nothing is showing up--all IP Addresses are null.

If, as a test, I use the fluent approach, it works fine (also in the sample).

FYI, in your documentation, 8.3 Type Converters, you mention IChoTypeConverter, but I can't find that and used IChoValueConverter instead. Maybe that's my problem??

JimF42 commented 1 year ago

ChoEtlSample.zip

Cinchoo commented 1 year ago

Applied fix, pushed new version v1.2.1.58

JimF42 commented 1 year ago

Just tried it out, works great. Thanks for the quick turnaround.

JimF42 commented 1 year ago

Reader works fine (I didn't try the Lite version), but ChoCSVWriter doesn't seem to be firing it either.

Cinchoo commented 1 year ago

ChoCSVWriter works for me. Can't reproduce it.

Lite version, doesn't use converters, other features. It is simple reader, return values as text only.

JimF42 commented 1 year ago

I have an extremely simple example attached. In my normal program, my input class and output class would be different structures.

The output is in the \bin\debug\net7.0 folder after you run it. ChoEtlSample.zip

Cinchoo commented 1 year ago

You need to decorate each field with ChoCSVRecordField to pick up the converter by the framework.

internal class IpAddressRecordOut
{
    [ChoCSVRecordField]
    public string? Description { get; set; }

    [ChoCSVRecordField]
    [ChoTypeConverter(typeof(IpAddressTypeConverter))]
    public IPAddress? IPAddress { get; set; }
}

May be in future, will consider taking the converter without the field attribute.

JimF42 commented 1 year ago

OK. Thank you for your patience with me on this.