I'd like to return a dynamic DTO based on the url route to fill a grid similar the one generated natively by servicestack.
So if I call something like mydomain/col1-col2-col4-col6 instead of returning the full collection with all the columns and hiding the non interesting data on the client I'd like to build a dynamic DTO and return a collection of dynamic objects.
Everything works if you return a dynamic object with already known properties build as an anonymous object.
dynamic obj = new {id = i,col1="testcol1",col2="testcol2",col4="testcol3"};
If I want to choose witch property to add the only way I found was this :
dynamic obj=new ExpandoObject();
obj.id = i;
foreach (var col in columns)
{
switch (col)
{
case "col1":
obj.col1 = "testcol1";
break;
case "col2":
obj.col2 = "col 2";
break;
default:
break;
}
The result that appears when serialized si very different (check the pictures).
Is there a clean way to dynamically add proprerties to a DTO to return?