C# .net add property to expando object dynamically edit button Edit

Murugan Andezuthu Dharmaratnam | calendar 12 January 2022 | 1361

sample code to add property to a C# expando object dynamically

Sample Code

        public void AddProperty(ExpandoObject expando, string propertyName, object propertyValue)
            // ExpandoObject supports IDictionary so we can extend it like this
            var expandoDict = expando as IDictionary<string, object>;
            if (expandoDict.ContainsKey(propertyName))
                expandoDict[propertyName] = propertyValue;
                expandoDict.Add(propertyName, propertyValue);