I am facing an interesting problem right now.
I know it is not that pretty but I have to cope with it anyway.
I am calling a webservice that returns (array of string) something like that (by index)
0 – Table Name (“Employees”)
1 – List of all fields returned (“Id, Name, Birthdate”)
2 – First field value (“1”)
3 – Second field value (“Bobby”)
4 – Third field value (“1970-01-01”)
What I would like to accomplish is to create a object name after the index 0, having all the strings in the index 1 being all the properties and feed them with their proper value.
What would be the best way to accomplish this? I have started reading about the ExpandoObject but before going too far I would like to hear your take on this.
Regards
EDIT: I will have quite a few different tables to fetch the data from, that is what is causing me the problem.
It depends on your use-case but I doubt that
dynamicis the way to go here. I would just have aname-valuecollection like so:Then you can populate the values from the webservice and query the values by saying
etc. If you knew the types you could make this indexer of type
objectinstead and parse the values to their appropriate type and store them as those typed objects.The issue with
dynamicis that if the names of the fields are an unknown, how are you possibly going to write code that utilizes those fields?Dude, name-value collection all day every day.