`Dynamic` to a static class converter. Does it exist?
I am using the dynamic
type to read in a lot of JSON and process it. Frankly, I'd rather have intellisense. So I was wondering whether anyone has written a converter class that tak开发者_JS百科es a dynamic
object and generates a static class(es) out of it.
Check out the JSON C# Class Generator:
This application generates C# classes from a sample JSON text, so you can use strongly typed programming with JSON. It currently supports typed arrays, typed objects, integers, floats, booleans, strings and nullable types.
JavaScriptSerializer.ConvertToType is ideal for this. It maps matching properties to a static type, and ignores those that don't.
You do need to give it the static type, but I think converting a dynamic to a anon static is a code smell.
精彩评论