Enumerar variables localesEnumerating Locals

Importante

Visual Studio 2015, esta forma de implementar los evaluadores de expresión está en desuso.In Visual Studio 2015, this way of implementing expression evaluators is deprecated. Para obtener información acerca de cómo implementar los evaluadores de expresión de CLR, vea evaluadores de expresión de CLR y Managed expresión evaluador Sample.For information about implementing CLR expression evaluators, please see CLR Expression Evaluators and Managed Expression Evaluator Sample.

Cuando Visual Studio esté listo para rellenar el locales ventana, llama a EnumChildren en el IDebugProperty2 objeto devuelto desde GetMethodProperty (consulte GetMethodProperty implementar).When Visual Studio is ready to populate the Locals window, it calls EnumChildren on the IDebugProperty2 object returned from GetMethodProperty (see Implementing GetMethodProperty). IDebugProperty2::EnumChildrenDevuelve un IEnumDebugPropertyInfo2 objeto.IDebugProperty2::EnumChildren returns an IEnumDebugPropertyInfo2 object.

Esta implementación de IDebugProperty2::EnumChildren realiza las tareas siguientes:This implementation of IDebugProperty2::EnumChildren performs the following tasks:

  1. Se asegura de esto es que representa un método.Ensures this is representing a method.

  2. Usa el guidFilter argumento para determinar qué método se debe llamar en el IDebugMethodField objeto.Uses the guidFilter argument to determine which method to call on the IDebugMethodField object. Si guidFilter es igual a:If guidFilter equals:

    1. guidFilterLocals, llame a EnumLocals para obtener un IEnumDebugFields objeto.guidFilterLocals, call EnumLocals to obtain an IEnumDebugFields object.

    2. guidFilterArgs, llame a EnumArguments para obtener un IEnumDebugFields objeto.guidFilterArgs, call EnumArguments to obtain an IEnumDebugFields object.

    3. guidFilterLocalsPlusArgs, sintetizar una enumeración que combina los resultados de IDebugMethodField::EnumLocals y IDebugMethodField::EnumArguments.guidFilterLocalsPlusArgs, synthesize an enumeration that combines the results from IDebugMethodField::EnumLocals and IDebugMethodField::EnumArguments. Esta síntesis se representa mediante la clase CEnumMethodField.This synthesis is represented by the class CEnumMethodField.

  3. Crea una instancia de una clase (denominado CEnumPropertyInfo en este ejemplo) que implementa el IEnumDebugPropertyInfo2 de interfaz y contiene el IEnumDebugFields objeto.Instantiates a class (called CEnumPropertyInfo in this example) that implements the IEnumDebugPropertyInfo2 interface and contains the IEnumDebugFields object.

  4. Devuelve el IEnumDebugProperty2Info2 interfaz desde el CEnumPropertyInfo objeto.Returns the IEnumDebugProperty2Info2 interface from the CEnumPropertyInfo object.

Código administradoManaged Code

Este ejemplo muestra una implementación de IDebugProperty2::EnumChildren en código administrado.This example shows an implementation of IDebugProperty2::EnumChildren in managed code.

namespace EEMC  
{  
    public class CFieldProperty : IDebugProperty2  
    {  
        public HRESULT EnumChildren (  
                uint                    dwFields,  
                uint                    radix,  
            ref Guid                    guidFilter,   
                ulong                   attribFilter,   
                string                  nameFilter,   
                uint                    timeout,  
            out IEnumDebugPropertyInfo2 properties)   
        {  
            properties = null;  
            IEnumDebugFields fields = null;  

            // If this field is a method...  
            if (0 != ((uint) fieldKind & (uint) FIELD_KIND.FIELD_TYPE_METHOD))  
            {  
                IDebugMethodField methodField = (IDebugMethodField) field;  

                // Enumerate parameters.  
                if (guidFilter == FilterGuids.guidFilterArgs)  
                {  
                    methodField.EnumParameters(out fields);    
                }  
                // Enumerate local variables.  
                else if (guidFilter == FilterGuids.guidFilterLocals)  
                {  
                    methodField.EnumLocals(address, out fields);    
                }  
                // Enumerate all local variables, including invisible compiler temps.  
                else if (guidFilter == FilterGuids.guidFilterAllLocals)  
                {  
                    methodField.EnumAllLocals(address, out fields);    
                }  
                // Enumerate "this", if any, and all parameters and local variables.  
                else if (guidFilter == FilterGuids.guidFilterLocalsPlusArgs)  
                {  
                    IDebugClassField fieldThis   = null;  
                    IEnumDebugFields parameters = null;  
                    IEnumDebugFields locals     = null;  

                    methodField.GetThis(out fieldThis);  
                    methodField.EnumParameters(out parameters);  
                    methodField.EnumLocals(address, out locals);  

                    CEnumMethodField enumMethodField =   
                        new CEnumMethodField(fieldThis, parameters, locals);  
                    fields = (IEnumDebugFields) enumMethodField;  
                }  
                // Enumerate only "this".  
                else if (guidFilter == FilterGuids.guidFilterThis)  
                {  
                    IDebugClassField fieldThis   = null;  
                    methodField.GetThis(out fieldThis);  

                    CEnumMethodField enumMethodField =   
                        new CEnumMethodField(fieldThis, null, null);  
                    fields = (IEnumDebugFields) enumMethodField;  
                }  
                else throw new COMException();// E_FAIL  
            }  
            // Wrap a property enumerator around the field enumerator.  
            CEnumPropertyInfo propertiesInfo =   
                new CEnumPropertyInfo(provider, address, binder, radix, fields,   
                 (DEBUGPROP_INFO_FLAGS) dwFields);  

            properties = (IEnumDebugPropertyInfo2) propertiesInfo;  
            return COM.S_OK;  
        }  
    }  
}  

Código no administradoUnmanaged Code

Este ejemplo muestra una implementación de IDebugProperty2::EnumChildren en código no administrado.This example shows an implementation of IDebugProperty2::EnumChildren in unmanaged code.

STDMETHODIMP CFieldProperty::EnumChildren(   
        in DEBUGPROP_INFO_FLAGS        infoFlags,  
        in DWORD                       radix,  
        in REFGUID                     guidFilter,  
        in DBG_ATTRIB_FLAGS            attribFilter,  
        in LPCOLESTR                   pszNameFilter,  
        in DWORD                       timeout,  
        out IEnumDebugPropertyInfo2 ** ppchildren )  
{  
    if (ppchildren == NULL)  
        return E_INVALIDARG;  
    else  
        *ppchildren = 0;  

    //get enumeration  
    HRESULT hr;  
    IEnumDebugFields*     pfields    = NULL;  

    if (m_fieldKind & FIELD_TYPE_METHOD)  
    {  
        //-----------------------------------------------------  
        // A Method  

        IDebugMethodField*  pmethod    = NULL;  

        //enumerate the requested properties  
        hr = m_field->QueryInterface( IID_IDebugMethodField,  
            reinterpret_cast<void**>(&pmethod) );  
        if (FAILED(hr))  
            return hr;  

        if (guidFilter == guidFilterArgs)  
        {  
            hr = pmethod->EnumParameters( &pfields );    
        }  
        else if (guidFilter == guidFilterLocals)  
        {  
            hr = pmethod->EnumLocals( m_address, &pfields );  
        }  
        else if (guidFilter == guidFilterAllLocals)  
        {  
            hr = pmethod->EnumAllLocals( m_address, &pfields );  
        }  
        else if (guidFilter == guidFilterLocalsPlusArgs)  
        {  
            //we create a special enumerator for this  
            IDebugClassField* pfieldThis  = NULL;  
            IEnumDebugFields* pparameters = NULL;  
            IEnumDebugFields* plocals     = NULL;  

            pmethod->GetThis( &pfieldThis );  
            pmethod->EnumParameters( &pparameters );  
            pmethod->EnumLocals( m_address, &plocals );  

            CEnumMethodField* penumMethodField =  
                new CEnumMethodField( pfieldThis, pparameters, plocals );  
            if (pfieldThis != NULL)  
                pfieldThis->Release();  
            if (pparameters != NULL)  
                pparameters->Release();  
            if (plocals != NULL)  
                plocals->Release();  
            if (!penumMethodField)   
            {   
                hr = E_OUTOFMEMORY;  
            }  
            else  
            {  
                hr = penumMethodField->QueryInterface( IID_IEnumDebugFields,  
                        reinterpret_cast<void**>(&pfields) );  
                penumMethodField->Release();  
            }  
        }  
        else if (guidFilter == guidFilterThis )  
        {  
            IDebugClassField* pfieldThis  = NULL;  

            hr = pmethod->GetThis( &pfieldThis );  
            if (SUCCEEDED(hr))  
            {  
                CEnumMethodField* penumMethodField =  
                    new CEnumMethodField( pfieldThis, NULL, NULL );  
                pfieldThis->Release();  
                if (!penumMethodField)   
                {  
                    hr = E_OUTOFMEMORY;  
                }  
                else  
                {  
                    hr = penumMethodField->QueryInterface( IID_IEnumDebugFields,  
                        reinterpret_cast<void**>(&pfields) );  
                    penumMethodField->Release();  
                }  
            }  
        }  
        else  
        {  
            hr = E_FAIL;  
        }  

        pmethod->Release();  
        if (hr != S_OK)  
            return hr;  
    }  

    //create a property info enumeration around the field enumerator  
    CEnumPropertyInfo* pproperties =  
        new CEnumPropertyInfo( m_provider, m_address, m_binder,   
                               radix, pfields, infoFlags );  
    if (pfields != NULL)  
        pfields->Release();  
    if (pproperties == NULL)  
        return E_OUTOFMEMORY;  

    hr = pproperties->QueryInterface( IID_IEnumDebugPropertyInfo2,  
        reinterpret_cast<void**>(ppchildren) );  
    pproperties->Release();  

    return hr;  
}  

Vea tambiénSee Also

Implementación de ejemplo de variables locales Sample Implementation of Locals
Implementar GetMethodProperty Implementing GetMethodProperty
Contexto de evaluaciónEvaluation Context