Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Created February 20, 2020 02:13
Show Gist options
  • Save joe-oli/0eea6c6c6b86030c6b6f8157fdbd438d to your computer and use it in GitHub Desktop.
Save joe-oli/0eea6c6c6b86030c6b6f8157fdbd438d to your computer and use it in GitHub Desktop.
dynamic and ExpandoObject
IDictionary<string, object> expando = new ExpandoObject();
expando["foo"] = "bar";
dynamic d = expando;
Console.WriteLine(d.foo); // bar
//Example use case, convert XML payload. loop over the elements, e.g.
var doc = XDocument.Load(file);
IDictionary<string, object> expando = new ExpandoObject();
foreach (var element in doc.Root.Elements())
{
expando[element.Name.LocalName] = (string) element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment