c# - JSON to Dynamic Object vs. Strongly Typed Object -


i'm not sure if don't big picture or if miss benefits of parsing json-string dynamic object?

if have class this

class product {     public string name { get; set; }     public double price { get; set; }     public string category { get; set; } } 

and use httpclient object this

product product = await response.content.readasasync<product>(); 

what benefit code?

string content = await response.content.readasstringasync(); dynamic product = jobject.parse(content); 

if want use them need write

product.name 

with typed apporach @ least have intellisense. if service changes product dynamic approach doesn't me either because still need access mentioned above.

so missing? why should use dynamics or when?

you always prefer use strong type on dynamic (performance\convenience).

here cases use dynamic:

  1. when want parse xml , dont want work xelement's, xpath's etc.

  2. com interop - makes things easy , nice (try working excel\word , convinced).

  3. in cases it's nicer , readable use dynamic instead of reflection.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -