adding new properties in expando object in foreach loop
-
23-12-2019 - |
Question
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
Solution
var expando = new ExpandoObject() as IDictionary<string, Object>;
foreach (var s in allProperties)
{
expando.Add(s, string.Empty);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow