I'm using WMI and it gives me a ManagementCollectionObject that include a collection of objects in different types such as string, int64, array of int, array of string and so on.
WMI Code Generator generates different code for single value and array values. as below:
// getting single value
Console.WriteLine("Availability: {0}", queryObj["Availability"]);
// getting single array value
if(queryObj["AvailableJobSheets"] == null)
Console.WriteLine("AvailableJobSheets: {0}", queryObj["AvailableJobSheets"]);
else
{
String[] arrAvailableJobSheets = (String[])(queryObj["AvailableJobSheets"]);
foreach (String arrValue in arrAvailableJobSheets)
{
Console.WriteLine("AvailableJobShe开发者_Python百科ets: {0}", arrValue);
}
}
how can i distinguish whether the value of a property is array or not?
You could use Type.IsArray
:
if(queryObj["AvailableJobSheets"].GetType().IsArray)
// It's an array
精彩评论