Created
May 13, 2025 11:47
-
-
Save ddjerqq/deb6d7d62782014e2e02ffe779727ed1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static class ExpandoExt | |
{ | |
/// <summary> | |
/// Add a property to a dynamic object at runtime. | |
/// </summary> | |
/// <example> | |
/// dynamic expando = new ExpandoObject(); | |
/// expando.Name = "Brian"; | |
/// expando.Country = "USA"; | |
/// expando.AddProperty("Language", "English"); | |
/// </example> | |
/// <param name="expando">The dynamic object to which the property will be added.</param> | |
/// <param name="key">The name of the property to add.</param> | |
/// <param name="value">The value of the property to add.</param> | |
public static void AddProperty(this System.Dynamic.ExpandoObject expando, string key, object value) => | |
(expando as IDictionary<string, object>)[key] = value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage