Implementación de GetMethodProperty
Importante
En Visual Studio 2015, esta forma de implementar evaluadores de expresiones está en desuso. Para obtener información sobre cómo implementar evaluadores de expresiones CLR, vea Evaluadores de expresiones CLR y Ejemplo de evaluador de expresiones administradas.
Visual Studio llama a GetDebugProperty del motor de depuración (DE), que a su vez llama a GetMethodProperty para obtener información sobre el método actual en el marco de pila.
Esta implementación de IDebugExpressionEvaluator::GetMethodProperty
realiza las siguientes tareas:
Llama a GetContainerField, pasando el objeto IDebugAddress. El proveedor de símbolos (SP) devuelve un IDebugContainerField que representa el método que contiene la dirección especificada.
Obtiene el IDebugMethodField de .
IDebugContainerField
Crea una instancia de una clase (denominada
CFieldProperty
en este ejemplo) que implementa la interfaz IDebugProperty2 y contiene elIDebugMethodField
objeto devuelto por el SP.Devuelve la interfaz
IDebugProperty2
desde el objetoCFieldProperty
.
Código administrado
En este ejemplo se muestra una implementación de IDebugExpressionEvaluator::GetMethodProperty
en código administrado.
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;
}
}
}
Código no administrado
En este ejemplo se muestra una implementación de IDebugExpressionEvaluator::GetMethodProperty
en código no administrado.
[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;
}