C# .net add property to expando object dynamically Edit

Murugan Andezuthu Dharmaratnam | 12 January 2022 | 17

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);