A Coder's Blog
The class ExpandoObject from System.Dynamics represents an object whose members can be dynamically added and removed at run time. The ExpandoObject supports runtime binding and implements the DLR interface IDynamicMetaObjectProvider, allowing you to share the expandoobject written in c# with another language that supports DLR interop.
The structure of ExpandoObject is a Dictionary of type string, object…as you can see in the reference source ExpandoObject class.
I created a simple object with some attributes and methods:
Being a IDictionary<string, object> type, it allows me to print all the properties in the same way I’d do for a dictionary
output:
Name: John
Surname: Lastname
DateOfBirth: 12/12/1960 00:00:00
Mood: happy
PresentYourself: System.Action
ChangeMood: System.Action`1[System.String]
Thanks to dynamic binding I’m able to access the properties of my ExpandoObject in a simple way e.g. person.Mood…without the need of using GetProperty() GetAttribute() etc
output:
sad
Hello! My name is John