MOF Arrays

[This is preliminary documentation and subject to change.]

MOF supports many different types of arrays, such as arrays of object references and embedded objects in addition to more standard string and numeric arrays. All arrays must be one-dimensional. Array dimensions vary at run time and are implemented internally as SAFEARRAY types. Arrays are initialized by specifying values of the appropriate type in a comma-separated list.

All elements in an array must be either values of the same type or NULL values. If the elements of an array are of type object, then any object is allowed in the array. If a specific type is declared, then only objects of that class or any of its subclasses are allowed.

To specify an array in a class declaration, use brackets after the property identifer.

class ArrayDataClass
{
    string strArray1[];
    string strArray2[] = {"hello", "there"};
    sint32 dwArray1[] = {1,2,3};
    EmbedClass objArray[];
};
instance of ArrayDataClass
{
    strArray1 = { "1.2.3.4", "1.2.3.5", "1.2.3.7"};
    strArray2 = {
            "select * from RegistryKeyChangeEvent",
            "select * from RegistryValueChangeEvent",
            "select * from RegistryTreeChangeEvent"};
    dwArray  = { 1, 2, 3, 5, 6 };
    objArray = {instance of EmbedClass{PropOfClass=3}, 
                instance of EmbedClass(PropOfClass=4};};
}
 

Arrays of references are simply arrays of object path strings:

instance of ClassWithRefArray
{
    refArray = {"Disk.Name=\"C:\"", "Disk.Name=\"E:\"";};
}

Arrays can be used with methods in class declarations only as parameters; they are not allowed to function as return values that are not output parameters. Arrays can be unbounded or have an explicit size, as is illustrated below:

Class MyClass
{
    sint32 MyMethod1 ([in] Win32LogicalDisk DiskArray1[]);
    sint32 MyMethod2 ([in] Win32LogicalDisk DiskArray2[32]);
}

WBEM implements bounded and unbounded arrays as SAFEARRAYS, expanding an array's size if necessary. When an array is declared with an explicit size, this size is stored as a qualifier and treated as the suggested maximum size. The explicit size has no affect on the actual data.