Implémenter GetMethodProperty

Important

Dans Visual Studio 2015, cette façon d’implémenter des évaluateurs d’expression est déconseillée. Pour plus d’informations sur l’implémentation d’évaluateurs d’expression CLR, consultez l’exemple d’évaluateur d’expression CLR et d’évaluateur d’expression managée.

Visual Studio appelle le moteur de débogage (DE) GetDebugProperty, qui à son tour appelle GetMethodProperty pour obtenir des informations sur la méthode actuelle sur le frame de pile.

Cette implémentation effectue IDebugExpressionEvaluator::GetMethodProperty les tâches suivantes :

  1. Appelle GetContainerField, en passant l’objet IDebugAddress . Le fournisseur de symboles (SP) retourne un champ IDebugContainerField représentant la méthode qui contient l’adresse spécifiée.

  2. Obtient l’IDebugMethodField à partir du IDebugContainerField.

  3. Instancie une classe (appelée CFieldProperty dans cet exemple) qui implémente l’interface IDebugProperty2 et contient l’objet IDebugMethodField retourné par le fournisseur de services.

  4. Retourne l’interface IDebugProperty2 de l’objet CFieldProperty .

Code managé

Cet exemple montre une implémentation de IDebugExpressionEvaluator::GetMethodProperty code managé.

namespace EEMC
{
    [GuidAttribute("462D4A3D-B257-4AEE-97CD-5918C7531757")]
    public class EEMCClass : IDebugExpressionEvaluator
    {
        public HRESULT GetMethodProperty(
                IDebugSymbolProvider symbolProvider,
                IDebugAddress        address,
                IDebugBinder         binder,
                int                  includeHiddenLocals,
            out IDebugProperty2      property)
        {
            IDebugContainerField containerField = null;
            IDebugMethodField methodField       = null;
            property = null;

            // Get the containing method field.
            symbolProvider.GetContainerField(address, out containerField);
            methodField = (IDebugMethodField) containerField;

            // Return the property of method field.
            property = new CFieldProperty(symbolProvider, address, binder, methodField);
            return COM.S_OK;
        }
    }
}

Code non managé

Cet exemple montre une implémentation du IDebugExpressionEvaluator::GetMethodProperty code non managé.

[CPP]
STDMETHODIMP CExpressionEvaluator::GetMethodProperty(
        in IDebugSymbolProvider *pprovider,
        in IDebugAddress        *paddress,
        in IDebugBinder         *pbinder,
        in BOOL                  includeHiddenLocals,
        out IDebugProperty2    **ppproperty
    )
{
    if (pprovider == NULL)
        return E_INVALIDARG;

    if (ppproperty == NULL)
        return E_INVALIDARG;
    else
        *ppproperty = 0;

    HRESULT hr;
    IDebugContainerField* pcontainer = NULL;

    hr = pprovider->GetContainerField(paddress, &pcontainer);
    if (FAILED(hr))
        return hr;

    IDebugMethodField*    pmethod    = NULL;
    hr = pcontainer->QueryInterface( IID_IDebugMethodField,
            reinterpret_cast<void**>(&pmethod));
    pcontainer->Release();
    if (FAILED(hr))
        return hr;

    CFieldProperty* pfieldProperty = new CFieldProperty( pprovider,
                                                         paddress,
                                                         pbinder,
                                                         pmethod );
    pmethod->Release();
    if (!pfieldProperty)
        return E_OUTOFMEMORY;

    hr = pfieldProperty->Init();
    if (FAILED(hr))
    {
        pfieldProperty->Release();
        return hr;
    }

    hr = pfieldProperty->QueryInterface( IID_IDebugProperty2,
            reinterpret_cast<void**>(ppproperty));
    pfieldProperty->Release();

    return hr;
}