Cristian
Cristian

Reputation: 111

Removing a property in ExpandoObject

I am using an API to get a collection of JSON responses and I am putting them in an ExpandoObject result. The property I want to delete is in result.data.attributes.image_url for example. I don't need it and wish to remove it from the entire collection. So far I've tried:

result.data.attributes.Remove("image_url"); 

However I am getting the message that ExpandoObject does not have a "Remove" method. How exactly can I do this? In python I would just use the del keyword to delete a dataframe's column. What is a C# equivalent to this?

Upvotes: 1

Views: 1104

Answers (1)

mxmissile
mxmissile

Reputation: 11673

First cast to a dictionary, then you should be able to call Remove().

var dict = (IDictionary<string, object>) result.data.attributes;
dict.Remove("image_url");

Or an all-in-one-line version, IMO harder to read though:

((IDictionary<string, object>) result.data.attributes).Remove("image_url");

Upvotes: 2

Related Questions