mercredi 8 avril 2015

linq select using reflection

I have a class like this, a class List, a list of string list



class Test
{
public string AAA{get;set;}
public string BBB{get;set;}
}

List<Test> test;

List<List<string>> output;


I want put the content from test to output. I am now using linq to transfer it as below.



output[0] = test.Selete(x=>x.AAA).ToList();
output[1] = test.Selete(x=>x.BBB).ToList();


If this class has 10 properties, I must write 10 line of code to transfer it. I got a keyword "reflection" but I have no idea how to use it on my code. Any suggestion will be appreciated.






Aucun commentaire:

Enregistrer un commentaire