I have a List of object came to me by serialization. But I know following:
- The list is not Empty
All types of the list have the same type. I can know this type only dynamically. For example:
list[0].GetType()
How to convert all list to Generic List using above mentioned conditions ?
P.S. I deserialize an array of objects came to me in JSON
{
"Message": [
{
"__type": "GameResponse:#Bridge3.Server",
"GameId": 1,
"GameName": "Game1 ",
"PlayerId": 1
},
{
"__type": "GameResponse:#Bridge3.Server",
"GameId": 2,
"GameName": "Game2 ",
"PlayerId": 1
}
}
list.OfType<TheType>(). However, the OP's apparent situation is that the type is unknown at compile timedynamicin that case. No need for reflection, unless you want to convert the data to some sort ofDictionary<string,object>such as a DataTable or the like.whyof my question: What is usage?