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:
when want parse xml , dont want work xelement's, xpath's etc.
com interop - makes things easy , nice (try working excel\word , convinced).
in cases it's nicer , readable use dynamic instead of reflection.
Comments
Post a Comment