jeudi 14 mars 2019

Spliting object using relfection

I have the following object type

public class TestClass
{
    public string Property_1;
    public string Property_2;
    public int property_3;
    public DateTime TimeStame;
}

And my data source is returning a list of these

List<TestClass> DataResponse;

I am trying to group all data so that all Property_1's are grouped by date, and the same for all other properties. So essentially I end up with:

Dictionary<DateTime, List<Property_1>>
Dictionary<DateTime, List<Property_2>>
Dictionary<DateTime, List<Property_3>>

I can iterate the properties using:

foreach (var property in typeof(TestClass).GetProperties())
{

}

But I am a little unsure how to use linq to populate the dictionaries.

Any help would be great! Thanks





Aucun commentaire:

Enregistrer un commentaire