Partager via


IDebugCustomAttributeQuery::GetCustomAttributeByName

Retrieves a custom attribute given its name.

HRESULT GetCustomAttributeByName(
   LPCOLESTR pszCustomAttributeName,
   BYTE*     ppBlob,
   DWORD*    pdwLen
);
int GetCustomAttributeByName(
   string    pszCustomAttributeName,
   ref int[] ppBlob,
   out uint  pdwLen
);

Parameters

  • pszCustomAttributeName
    [in] Name of the custom attribute.

  • ppBlob
    [in,out] Array of bytes that contain the custom attribute data.

  • pdwLen
    [out] Length in bytes of the ppBlob parameter.

Return Value

If successful, returns S_OK. If custom attribute does not exist, returns S_FALSE. Otherwise, returns an error code.

Example

The following example shows how to implement this method for a CDebugClassFieldSymbol object that exposes the IDebugCustomAttributeQuery interface.

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

See Also

Reference

IDebugCustomAttributeQuery