Created
January 16, 2022 21:21
-
-
Save RachidAZ/1bedacbec5a5a9a14fac4ee52e8ffa26 to your computer and use it in GitHub Desktop.
create and set dynamic object in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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