Mgmtclassgen.exe uses the System.Management.ManagementClass.GetStronglyTypedClassCode method. Therefore, you can use any custom code provider to generate code in managed languages other than C#, Visual Basic, and JScript.
Note that generated classes are bound to the schema for which they are generated. If the underlying schema changes, you must regenerate the class if you want it to reflect changes to the schema.
The following table shows how WMI Common Information Model (CIM) types map to data types in a generated class:
|
CIM type
|
Data type in the generated class
|
| CIM_SINT8 | SByte |
| CIM_UINT8 | Byte |
| CIM_SINT16 | Int16 |
| CIM_UINT16 | UInt16 |
| CIM_SINT32 | Int32 |
| SIM_UINT32 | UInt32 |
| CIM_SINT64 | Int64 |
| CIM_UINT64 | UInt64 |
| CIM_REAL32 | Single |
| CIM_REAL64 | Double |
| CIM_BOOLEAN | Boolean |
| CIM_String | String |
| CIM_DATETIME | DateTime or TimeSpan |
| CIM_REFERENCE | ManagementPath |
| CIM_CHAR16 | Char |
| CIM_OBJECT | ManagementBaseObject |
| CIM_IUNKNOWN | Object |
| CIM_ARRAY | Array of the above mentioned objects |
Note the following behaviors when you generate a WMI class:
-
It is possible for a standard public property or method to have the same name as an existing property or method. If this occurs, the tool changes the name of the property or method in the generated class to avoid naming conflicts.
-
It is possible for the name of a property or method in a generated class to be a keyword in the target programming language. If this occurs, the tool changes the name of the property or method in the generated class to avoid naming conflicts.
-
In WMI, qualifiers are modifiers that contain information to describe a class, instance, property, or method. WMI uses standard qualifiers such as Read, Write, and Key to describe a property in a generated class. For example, a property that is modified with a Read qualifier is defined only with a property get accessor in the generated class. Because a property marked with the Read qualifier is intended to be read-only, a set accessor is not defined.
-
A numeric property can be modified by the Values and ValueMaps qualifiers to indicate that the property can be set only to specified permissible values. An Enumerations in the Common Type System is generated with these Values and ValueMaps and the property is mapped to the enumeration.
-
The WMI uses the term singleton to describe a class that can have only one instance. Therefore, the default constructor for a singleton class will initialize the class to the only instance of the class.
-
A WMI class can have properties that are objects. When you generate a strongly-typed class for this type of WMI class, you should consider generating strongly-typed classes for the types of the embedded object properties. This will allow you to access the embedded objects in a strongly-typed manner. Note that the generated code might not be able to detect the type of the embedded object. In this case, a comment will be created in the generated code to notify you of this issue. You can then modify the generated code to type the property to the other generated class.
-
In WMI, the data value of the CIM_DATETIME data type can represent either a specific date and time or a time interval. If the data value represents a date and time, the data type in the generated class is DateTime. If the data value represents a time interval, the data type in the generated class is TimeSpan.
You can alternately generate a strongly-typed class using the Server Explorer Management Extension in Visual Studio .NET.
For more information about WMI, see Windows Management Instrumentation (WMI) in .NET Framework and the Windows Management Instrumentation topic in the Platform SDK documentation.