Sdílet prostřednictvím


Implementace GetMethodProperty

Důležité

V sadě Visual Studio 2015 je tento způsob implementace vyhodnocovačů výrazů zastaralý. Informace o implementaci vyhodnocovačů výrazů CLR najdete v tématu vyhodnocovače výrazů CLR a ukázka vyhodnocovače spravovaných výrazů.

Visual Studio volá metodu GetDebugProperty ladicího modulu, která následně volá GetMethodProperty k získání informací o aktuální metodě v rámci zásobníku.

Tato implementace IDebugExpressionEvaluator::GetMethodProperty provádí následující úlohy:

  1. Volá GetContainerField, předávání IDebugAddress objektu. Zprostředkovatel symbolů (SP) vrátí IDebugContainerField představující metodu, která obsahuje zadanou adresu.

  2. Získá IDebugMethodField z IDebugContainerField.

  3. Vytvoří instanci třídy (volána CFieldProperty v tomto příkladu), která implementuje IDebugProperty2 rozhraní a obsahuje IDebugMethodField objekt vrácený z SP.

  4. IDebugProperty2 Vrátí rozhraní z objektuCFieldProperty.

Spravovaný kód

Tento příklad ukazuje implementaci spravovaného IDebugExpressionEvaluator::GetMethodProperty kódu.

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

Nespravovaný kód

Tento příklad ukazuje implementaci IDebugExpressionEvaluator::GetMethodProperty v nespravovaném kódu.

[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;
}