EnumerateKeyValues 方法是客户端将转向的第一种方法,用于枚举对象上的所有键(这包括父模型树中任意位置实现的所有键)。 请务必注意,EnumerateKeyValues 将枚举对象树中重复名称定义的任何键;但是 -- GetKeyValue 和 SetKeyValue 等方法只会作具有给定名称的键的第一个实例,如深度优先遍历发现。
语法
HRESULT EnumerateKeyValues(
  IKeyEnumerator **enumerator
);
参数
enumerator
对象上所有键(及其所有父模型)及其值和元数据的枚举器作为 IKeyEnumerator返回。
返回值
此方法返回指示成功或失败的 HRESULT。
言论
代码示例
ComPtr<IModelObject> spObject; /* get the object you want to enumerate */
ComPtr<IKeyEnumerator> spEnum;
if (SUCCEEDED(spObject->EnumerateKeyValues(&spEnum)))
{
    HRESULT hr = S_OK;
    while (SUCCEEDED(hr))
    {
        BSTR keyName;
        ComPtr<IModelObject> spKeyValue;
        hr = spEnum->GetNext(&keyName, &spKeyValue, nullptr);
        if (SUCCEEDED(hr))
        {
            // keyName contains the name of the key
            // spKeyValue contains the value of the key
            SysFreeString(keyName);
        }
    }
    // hr == E_BOUNDS  : We hit the end of the enumerator
    // hr == E_ABORT   : User is requesting interruption of the 
    // operation / stop immediately and flow the error
}
要求
| 要求 | 价值 | 
|---|---|
| 标头 | dbgmodel.h |