我正在循環查找字段的動態對象上的屬性,除了我無法弄清楚如何安全地評估它是否存在而不會拋出一個例外。如何安全地檢查動態對象是否有字段
foreach (dynamic item in routes_list["mychoices"])
{
// these fields may or may not exist
int strProductId = item["selectedProductId"];
string strProductId = item["selectedProductCode"];
}
感謝您的幫助
乾杯!
的[動態,如何測試是否可能重複一個屬性是可用](http://stackoverflow.com/questions/2998954/dynamic-how-to-test-if-a-property-is-available) –
你爲什麼試圖使用foreach(動態項目螞蟻只是var –
這是最好的回答 http://stackoverflow.com/questions/2839598/how-to-detect-if-a-property-exists-on-a-dynamic-object-in-c – Ehsan