0

以下のコード whenMyGlobals.ListOfItemsToControl[i].sItemNameに object が存在しない場合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
    .....
}
4

1 に答える 1