IModelObject::GetKey 메서드(dbgmodel.h)

GetKey 메서드는 이름으로 지정된 키의 값(및 연결된 메타데이터)을 가져옵니다. 대부분의 클라이언트는 GetKeyValue 메서드를 대신 활용해야 합니다. 키가 속성 접근자인 경우 이 메서드를 호출하면 IModelObject에 박스된 속성 접근자(IModelPropertyAccessor 인터페이스)가 반환됩니다. GetKeyValue와 달리 이 메서드는 GetValue 메서드를 호출하여 키의 기본 값을 자동으로 resolve 않습니다. 그 책임은 발신자의 책임입니다.

구문

HRESULT GetKey(
  PCWSTR                          key,
  _COM_Errorptr_opt_ IModelObject **object,
  IKeyStore                       **metadata
);

매개 변수

key

값을 가져올 키의 이름입니다.

object

키의 값은 이 인수에 반환됩니다. 일부 오류의 경우 메서드가 실패한 HRESULT를 반환하더라도 이 인수에서 확장된 오류 정보가 전달될 수 있습니다.

metadata

이 키와 연결된 메타데이터 저장소는 필요에 따라 이 인수에 반환됩니다.

반환 값

이 메서드는 성공 또는 실패를 나타내는 HRESULT를 반환합니다. E_BOUNDS 반환 값(또는 경우에 따라 E_NOT_SET)은 키를 찾을 수 없음을 나타냅니다.

설명

코드 예제

ComPtr<IModelObject> spProcess; /* get a process object */

ComPtr<IModelObject> spIdKey;
if (SUCCEEDED(spProcess->GetKey(L"Id", &spIdKey, nullptr)))
{
    // Unlike GetKeyValue(), spIdKey may contain a value or it may be a 
    // *property* that needs to be fetched.  Check!
    ModelObjectKind kind;
    if (SUCCEEDED(spIdKey->GetKind(&kind)))
    {
        if (kind == ObjectPropertyAccessor)
        {
            VARIANT vtProp; 
            if (SUCCEEDED(spIdKey->GetIntrinsicValue(&vtProp)))
            {
                // There is an *in-process* guarantee because of 
                // ObjectPropertyAccessor that the IUnknown is an IModelPropertyAccessor
                IModelPropertyAccessor *pPropertyAccessor = 
                    static_cast<IModelPropertyAccessor *>(vtProp.punkVal);

                // Fetch the value underneath the property accessor.  GetKeyValue 
                // would have done this for us.
                ComPtr<IModelObject> spId;
                if (SUCCEEDED(pPropertyAccessor->GetValue(L"Id", spProcess.Get(), &spId)))
                {
                    // spId now contains the value of the id.  Unbox with GetIntrinsicValueAs.
                }

                VariantClear(&vtProp);
            }
        }
        else
        {
            // spIdKey contains the value.  Unbox with GetIntrinsicValueAs.
        }
    }
}

요구 사항

요구 사항
헤더 dbgmodel.h

추가 정보

IModelObject 인터페이스