Convert WMI CimType to System.Type
- by Anonymous Coward
I am trying to write a generic extension to turn a ManagementObjectCollection into a DataTable. This is just to make things easier for a startup script/program I am writing. I have ran into a problem with CimType. I have included the code I have written so far below.
public static DataTable GetData(this ManagementObjectCollection objectCollection)
{
DataTable table = new DataTable();
foreach (ManagementObject obj in objectCollection)
{
if (table.Columns.Count == 0)
{
foreach (PropertyData property in obj.Properties)
{
table.Columns.Add(property.Name, property.Type);
}
}
DataRow row = table.NewRow();
foreach (PropertyData property in obj.Properties)
{
row[property.Name] = property.Value;
}
table.Rows.Add(row);
}
return table;
}
}
I have found the a method which I think will work at http://www.devcow.com/blogs/adnrg/archive/2005/09/23/108.aspx. However it seems to me like there may be a better way, or even a .net function I am overlooking.