重要
在 Visual Studio 2015 中,已取代這種實作運算式評估工具的方式。 如需實作 CLR 運算式評估工具的相關資訊,請參閱 CLR 運算式評估工具和受控運算式評估工具範例。
Visual Studio 會呼叫偵錯引擎 (DE) 的 GetDebugProperty,接著會呼叫 GetMethodProperty 以取得堆疊框架上目前方法的相關資訊。
這個 IDebugExpressionEvaluator::GetMethodProperty 實作會執行下列工作:
呼叫 GetContainerField,傳入 IDebugAddress 物件。 符號提供者 (SP) 會傳回 IDebugContainerField,代表包含指定位址的方法。
從
IDebugContainerField取得 IDebugMethodField。具現化類別 (在此範例中稱為
CFieldProperty),該類別會實作 IDebugProperty2 介面,並包含從 SP 傳回的IDebugMethodField物件。從
CFieldProperty物件傳回IDebugProperty2介面。
Managed 程式碼
此範例說明以受控碼實作的 IDebugExpressionEvaluator::GetMethodProperty。
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;
}
}
}
非受控碼
此範例說明以非受控碼實作的 IDebugExpressionEvaluator::GetMethodProperty。
[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;
}