Metodo IModelObject::GetKey (dbgmodel.h)

Il metodo GetKey otterrà il valore di (e i metadati associati a) una determinata chiave in base al nome. La maggior parte dei client deve usare invece il metodo GetKeyValue. Se la chiave è una funzione di accesso alla proprietà, la chiamata a questo metodo restituirà la funzione di accesso della proprietà (un'interfaccia IModelPropertyAccessor ) in un oggetto IModelObject. A differenza di GetKeyValue, questo metodo non risolve automaticamente il valore sottostante della chiave chiamando il metodo GetValue. Questa responsabilità è quella del chiamante.

Sintassi

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

Parametri

key

Nome della chiave per ottenere un valore.

object

Il valore della chiave verrà restituito in questo argomento. In alcuni casi di errore, le informazioni di errore estese possono essere passate in questo argomento anche se il metodo restituisce un errore HRESULT.

metadata

L'archivio metadati associato a questa chiave verrà restituito facoltativamente in questo argomento.

Valore restituito

Questo metodo restituisce HRESULT che indica l'esito positivo o l'errore. I valori restituiti E_BOUNDS (o E_NOT_SET in alcuni casi) indicano che la chiave non è stata trovata.

Commenti

Codice di esempio

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.
        }
    }
}

Requisiti

Requisito Valore
Intestazione dbgmodel.h

Vedi anche

Interfaccia IModelObject