Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fasteddys opened this issue Apr 5, 2024 · 0 comments

Comments

@fasteddys
Copy link

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;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant