Condividi tramite


IDebugCustomAttributeQuery::GetCustomAttributeByName

Recupera un attributo personalizzato in base al nome.

Sintassi

int GetCustomAttributeByName(
    string    pszCustomAttributeName,
    ref int[] ppBlob,
    out uint  pdwLen
);

Parametri

pszCustomAttributeName
[in] Nome dell'attributo personalizzato.

ppBlob
[in,out] Matrice di byte che contengono i dati dell'attributo personalizzato.

pdwLen
[out] Lunghezza in byte del ppBlob parametro.

Valore restituito

Se l'esito è positivo, restituisce S_OK. Se l'attributo personalizzato non esiste, restituisce S_FALSE. In caso contrario, verrà restituito un codice di errore.

Esempio

Nell'esempio seguente viene illustrato come implementare questo metodo per un oggetto CDebugClassFieldSymbol che espone l'interfaccia IDebugCustomAttributeQuery .

HRESULT CDebugClassFieldSymbol::GetCustomAttributeByName(
    LPCOLESTR pszCustomAttributeName,
    BYTE *pBlob,
    DWORD *pdwLen
)
{
    HRESULT hr = S_FALSE;
    CComPtr<IMetaDataImport> pMetadata;
    mdToken token = mdTokenNil;
    CComPtr<IDebugField> pField;
    CComPtr<IDebugCustomAttributeQuery> pCA;

    ASSERT(IsValidWideStringPtr(pszCustomAttributeName));
    ASSERT(IsValidWritePtr(pdwLen, ULONG*));

    METHOD_ENTRY( CDebugClassFieldSymbol::GetCustomAttributeByName );

    IfFalseGo( pszCustomAttributeName && pdwLen, E_INVALIDARG );

    IfFailGo( m_spSH->GetMetadata( m_spAddress->GetModule(), &pMetadata ) );

    IfFailGo( CDebugCustomAttribute::GetTokenFromAddress( m_spAddress, &token) );
    IfFailGo( CDebugCustomAttribute::GetCustomAttributeByName( pMetadata,
              token,
              pszCustomAttributeName,
              pBlob,
              pdwLen ) );
Error:

    METHOD_EXIT( CDebugClassFieldSymbol::GetCustomAttributeByName, hr );
    return hr;
}

Vedi anche