I was assigned with a problematic (at least for me) job for my internship. The project has a C# object that looks like this:
public class Person
{
int Id { get; set; }
string Name { get; set; }
string OtherInfo { get; set; } //json string for a dynamic info
}
So in the database that class' table tblPersons
looks like this:
Id Name OtherInfo
1 John Doe {"Gender":"Male","City":"New York"}
2 James Bradley {"Gender":"Male","City":"Los Angeles"}
So when I say "dynamic info" I meant that the properties of the json string in the otherinfo column may change. This property is defined in another table called 'tblOtherInfoDetails'
Id Name Type
1 Gender Text
2 City Text
Now to the task, I have to create a Persons list table containing the other info as column in the table. Like so; (DESIRED HTML TABLE OUTPUT)
Id Name Gender City
1 John Doe Male New York
2 James Bradley Male Los Angeles
But I am puzzled on how to do / display this. I can create another class like:
public class PersonsList
{
string Name..
string Gender..
string City...
}
And populate it with data by deserializing the json string and adding the name to display in the view but the problem is when the OtherInfo details is changed, the program will not work anymore. I need some way to create a dynamic class on the fly that can be populated by different properties and to be displayed in the screen. But I am puzzled on how to do that or if that is possible as I am just new in C#. Any help or suggestion will be highly appreciated..