Background
I have a list of generic objects. Each generic object has a specific field I need to remove.
I create the list like this.
list = new List<Object>();
list = JsonConvert.DeserializeObject<List<T>>(OutJson, new BooleanJsonConverter());
However i need to then remove a item from every object in that list. However i don't know how many or what objects are in the list. I do know that there will always be a field that i need to remove however.
Pseudocode
I think I need to do something like this, but in a generic way.
//Loop through list objects, and for each object, loop through its
//properties. If any of the properties match a string, remove
//that property from the object.
foreach (var object in list)
{
foreach (var item in object)
{
if(item.ToUpper() == "SpecificKey")
{
list.Remove(item);
}
}
}
Question
How do I loop through the generic object in a list and remove a specific item if it is present?