Azhar Kiani
Azhar Kiani

Reputation: 353

adding new properties in expando object in foreach loop

I have to add new properties in expando object in foreach loop but I am not able to see a way to do it. Here is the example:

var allProperties = new List { "Name", "Email", "Roles" }; allProperties.AddRange(metaDataModel.GetFormattedFolders());

dynamic expando = new ExpandoObject();
foreach (var s in allProperties)
{
    expando.s = string.Empty;
}

It consider 's' as a property instead of considering value of 's' as property name.

Thanks

Upvotes: 2

Views: 4093

Answers (1)

Damith
Damith

Reputation: 63105

var expando = new ExpandoObject() as IDictionary<string, Object>;
foreach (var s in allProperties)
{
    expando.Add(s, string.Empty);
}

Upvotes: 7

Related Questions