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

Display header with name and type, while reading data, objects, how to get attribute name and type (nullabale) #315

Open fasteddys opened 1 month ago

fasteddys commented 1 month ago

Hello, in a header I have to display the name + data type of the properties from a list of C# objects (from file or stream etc).

Can you help me, is there a function in CHO that can take any POCO class / record object, and give me the nested nullable & non-nullable properties type along with the names of the properties. I wrote some code, but run into issues when its nullable.

Most of the time the objects are flat, so if I can get that it would solve 95% of my issues, would be helpful if I knew how to connect this up natively with CHOetl


For a nested C# object with more levels, I converted to expando... I did this with SO help.

private static Dictionary<string, object> FlattenDimensions(dynamic[] dimensions)
    {
        var flattened = new Dictionary<string, object>();
        foreach (var dimension in dimensions)
        {
            var dict = (IDictionary<string, object>)dimension;
            foreach (var item in dict)
            {
                flattened.Add(item.Key, item.Value);
            }
        }
        return flattened;
    }