CP-36392: Refactor for loop into if statement

For loop acts as if statement. Changed to address static analysis flag.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-09-15 14:47:26 +01:00
parent 2d1e6dcb92
commit c9e65a3000
No known key found for this signature in database
GPG Key ID: 55F556F9A25CB037

View File

@ -486,10 +486,16 @@ namespace XenOvf
try
{
searcher = new ManagementObjectSearcher(@"select * from Win32_ComputerSystem");
foreach (ManagementObject mgtobj in searcher.Get())
var mgtObjs = searcher.Get();
// only want one.
if (mgtObjs.Count > 0)
{
Win32_ComputerSystem = mgtobj; // only want one.
break;
using (var iterator = mgtObjs.GetEnumerator())
{
iterator.MoveNext();
Win32_ComputerSystem = (ManagementObject) iterator.Current;
}
}
log.Debug("OVF.CollectionInformation Win32_ComputerSystem.1");
}
@ -511,11 +517,18 @@ namespace XenOvf
try
{
searcher = new ManagementObjectSearcher(@"select * from Win32_Processor");
foreach (ManagementObject mgtobj in searcher.Get())
var mgtObjs = searcher.Get();
// only want one.
if (mgtObjs.Count > 0)
{
Win32_Processor.Add(mgtobj); // only want one.
break;
using (var iterator = mgtObjs.GetEnumerator())
{
iterator.MoveNext();
Win32_Processor.Add((ManagementObject) iterator.Current);
}
}
log.DebugFormat("OVF.CollectionInformation Win32_Processor.{0}", Win32_Processor.Count);
}
catch (Exception ex)