Flip ExpandoObject

I wrote an excellent function that will take system.object , reflect on its properties and serialize the object into a JSON string. It looks like this:

 public class JSONSerializer { public string Serialize(object obj) 

Now I want to be able to do this to serialize dynamic / ExpandoObject, but since my serializer uses reflection, it is not able to do this. What is the workaround?

 public class Test { public dynamic MakeDynamicCat() { dynamic newCat = new ExpandoObject(); newCat.Name = "Polly"; newCat.Pedigree = new ExpandoObject(); newCat.Pedigree.Breed = "Whatever"; return newCat; } public void SerializeCat() { new JSONSerializer().Serialize(MakeDynamicCat()); } } 
+6
reflection dynamic expando expandoobject
source share
2 answers

I think this question is very similar: How do I reflect the elements of a dynamic object?

At least the answers will also help you.

+2
source share

I would suggest using JSON.NET for serialization. Version 3.5 supports the serialization of dynamic objects (for example, expando). Anonymizing from JSON to a dynamic object takes a bit of effort, but it is also not too cumbersome. The following message lists:

Serialization of dynamic objects

0
source share

All Articles