在下面的代码中,当MyGlobals.ListOfItemsToControl[i].sItemName
对象中不存在时HWRes.HWResObj
,我想在不跳转到 catch 语句的情况下检测到这个问题。
我怎样才能做到这一点?
try
{
String HWTemp = "";
// Ref http://stackoverflow.com/questions/15628140/c-sharp-eliminate-switch-requirement
HWTemp = HWRes.HWResObj.GetType().GetProperty(MyGlobals.ListOfItemsToControl[i].sItemName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance).GetValue(HWRes.HWResObj, null).ToString();
// Somehow here I should detect if the value MyGlobals.ListOfItemsToControl[i].sItemName does not exist in the object HWRes.HWResObj
// Detect issue without jumping to catch
}
catch
{
// I dont want to go here when MyGlobals.ListOfItemsToControl[i].sItemName does not exist in the object HWRes.HWResObj
.....
}