Skip to content

Instantly share code, notes, and snippets.

@tdittmar tdittmar/dynamic_object.cs
Last active Dec 10, 2016

Embed
What would you like to do?
Creating a dynamic object in C#, for example to serialize it to JSON
dynamic test = new {
id = 12345,
additionalData = new
{
something = "Hello World",
subItems = new List<object>()
{
new {
test1 = "this",
test2 = "is"
test3 = "a"
test4 = "test"
},
new {
test1 = "this",
test2 = "is",
test3 = "the second",
test4 = "list entry"
}
}
}
};
public void Print(dynamic par)
{
Console.WriteLine(test.additionalData.something);
test.additionalData.subItems.Add(new { test1 = "third", test2 = "entry", test3 = "in", test4 = "list" });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.