I'm looking for ideas on better/safe way to access variables when using dynamic keyword. Most of the time
myDto.ipaddress = item["ipaddr"];
is perfectly fine, except sometimes these values aren't defined in the json and need to accessed without throwing a Null exception.
dynamic routes_list = json_serializer.DeserializeObject(System.Web.HttpUtility.UrlDecode(data));
for (int i = 0; i < routes_list["routes"].Length; i++)
{
var item = routes_list["routes"][i]
System.Collections.Generic.Dictionary<string, object> itemDict = item;
// having to repeat this too often
object snmask= string.Empty;
itemDict.TryGetValue("snmask", out snmask);
}
Thanks