开发者

`Dynamic` to a static class converter. Does it exist?

开发者 https://www.devze.com 2023-04-05 20:55 出处:网络
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 dyn

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号