I know how to gain access to management-objects. Lets say this one:
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
foreach (var nic in searcher.Get())
{
Console.WriteLine(nic["caption"]);
}
Now this nic[]-synthax is very bad to use. If I take a look at visual studios server explorer I see, that it fills up a property grid for each object I select. Smells like they are creating bindable classes there. Are there any libs or approaches to do the same? I would like to get a syntax like
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
foreach (var nic in searcher.Get())
{
Console.WriteLine((nic as Win32NetworkAdapter).Caption);
}
I just don’t want to waste my time implementing something new which was invented already!
WMI takes a query and returns an indeterminate set of results. The query is SQL-like, so it may return only certain columns. The properties grid simply enumerates each returned value into separate names and values. There’s no fixed column set for any query result. For this reason, you’ll need to explicitly fetch each one from the returned list.