How do I make the complex structure of an anonymous object public inside a dynamic
object?
Anonymous objects are flagged as internal
, so I'm looking for a creative way to work around this.
// This is the library I control
public void SendObject() {
var anonymous = new {
Text = "Test",
SubItem = new {
SubText = "Bla",
SubSub = new {
SubSubText = "Baha"
}
}
};
}
dynamic dyn = ExposeAnonymous(anonymous); // Perform voodoo
var result = ExternalLibrary.GetSpecialProperty(dyn);
// External library I don't control
public object GetSpecialProperty(dynamic dyn) {
return dyn.SubItem.SubSub.SubSubText;
}
The problem is when sending the dynamic
to other external libraries, that I don't control, you get an error like:
'object' does not contain a definition for 'SubItem'.