Quickly deanonymize dynamic typing
Dynamic types are useful when extracting values from data sources before structuring them, but I generally want to return to a static-typed context as soon as possible. .NET provides a built-in type, RouteValueDictionary, which lets you extract key-value pairs from a dynamic type object pretty easily.
Example code:
In this gist, I am reading a Google AdWords report response object, returned from reportRequest
, into a
CsvReader
object. I am converting each record to a dynamic
object, but quickly converting that object into
a RouteValueDictionary
object in the next Select()
statement.
From there I am formatting and reading the individual
columns, creating a new class of KeywordPerformanceStat
, which I will then insert into the database using Dapper