I have a variety of MVC view models to work with and each one contains a lot of information about the pages they generate. I need to take much of this information out of the view models and use a framework I wrote that makes it available client-side.
Unfortunately, when I try to serialize an entire view model to JSON, Newtonsoft returns empty-handed. So as a work-around, I have been manually building an object with an implicit type so that the information will get serialized to JSON.
However, this is tedious, and as such, I would like a simple way to iterate over all the members of the view model (or any other object for that matter) and transfer just the regular system types (strings, booleans, integers, and arrays of) etc.. over to a dictionary of string, object.
This is proving more difficult than I thought because I cannot seem to check the type property of its members to see if the object member is any one of those generic types or not. Is there an easy way to do that?
(BTW, I would like to avoid having to tag all the models with serialization attributes. There are too many of them.)