Skip to content

Instantly share code, notes, and snippets.

@RachidAZ
Created January 16, 2022 21:21
Show Gist options
  • Save RachidAZ/1bedacbec5a5a9a14fac4ee52e8ffa26 to your computer and use it in GitHub Desktop.
Save RachidAZ/1bedacbec5a5a9a14fac4ee52e8ffa26 to your computer and use it in GitHub Desktop.
create and set dynamic object in C#
using System.Dynamic;
dynamic record = new ExpandoObject();
AddProperty(record, "property_name", "property_value");
public static void AddProperty(ExpandoObject expando, string propertyName, object propertyValue)
{
var expandoDict = expando as IDictionary<string, object>;
if (expandoDict.ContainsKey(propertyName))
expandoDict[propertyName] = propertyValue;
else
expandoDict.Add(propertyName, propertyValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment