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()); } }
Water cooler v2
source share