Metodo IModelPropertyAccessor::GetValue (dbgmodel.h)

Il metodo GetValue è il getter per la funzione di accesso della proprietà. Viene chiamato ogni volta che un client desidera recuperare il valore sottostante della proprietà. Si noti che qualsiasi chiamante che ottiene direttamente una funzione di accesso di proprietà è responsabile del passaggio del nome della chiave e dell'oggetto istanza accurata (questo puntatore) al metodo GetValue della proprietà.

Sintassi

HRESULT GetValue(
  PCWSTR       key,
  IModelObject *contextObject,
  IModelObject **value
);

Parametri

key

Nome della chiave per ottenere un valore. Un chiamante che recupera direttamente una funzione di accesso di proprietà è responsabile del passaggio accurato di questa funzione.

contextObject

Oggetto context (istanza di questo puntatore) da cui è stata recuperata la funzione di accesso della proprietà.

value

Il valore sottostante della proprietà viene restituito qui.

Valore restituito

Questo metodo restituisce HRESULT che indica l'esito positivo o l'errore.

Commenti

Codice di esempio

// The full implementation class is shown for clarity.
class MyReadOnlyProperty :
    public Microsoft::WRL::RuntimeClass<
        Microsoft::WRL::RuntimeClassFlags<
            Microsoft::WRL::RuntimeClassType::ClassicCom
            >,
        IModelPropertyAccessor
        >
{
public:

    IFACEMETHOD(GetValue)(_In_ PCWSTR /*pwszKey*/, 
                          _In_ IModelObject * /*pContextObject*/, 
                          _COM_Errorptr_ IModelObject **ppValue)
    {
        HRESULT hr = S_OK;
        *ppValue = nullptr;

        VARIANT vtValue;
        vtValue.vt = VT_I4;
        vtValue.lVal = m_value;
        
        ComPtr<IModelObject> spValue;
        hr = GetManager()->CreateIntrinsicObject(ObjectIntrinsic, &vtValue, &spValue);
        if (SUCCEEDED(hr))
        {
            *ppValue = spValue.Detach();
        }

        return hr;
    }

    IFACEMETHOD(SetValue)(_In_ PCWSTR /*pwszKey*/, 
                          _In_ IModelObject * /*pContextObject*/, 
                          _In_ IModelObject * /*pValue*/)
    {
        // We are a read only property.
        return E_NOTIMPL;
    }

    HRESULT RuntimeClassInitialize(_In_ int value)
    {
        m_value = value;
        return S_OK;
    }

private:

    int m_value;
};

Requisiti

Requisito Valore
Intestazione dbgmodel.h

Vedi anche

Interfaccia IModelPropertyAcessor