Udostępnij przez


IDebugCustomAttributeQuery::IsCustomAttributeDefined

Określa, czy określony atrybut niestandardowy jest zdefiniowany.

Składnia

int IsCustomAttributeDefined(
    string pszCustomAttributeName
);

Parametry

pszCustomAttributeName
[in] Nazwa atrybutu niestandardowego.

Wartość zwracana

Jeśli atrybut niestandardowy jest zdefiniowany, zwraca wartość S_OK; w przeciwnym razie zwraca wartość S_FALSE.

Przykład

W poniższym przykładzie pokazano, jak zaimplementować tę metodę dla obiektu CDebugClassFieldSymbol , który uwidacznia interfejs IDebugCustomAttributeQuery .

HRESULT CDebugClassFieldSymbol::IsCustomAttributeDefined(
    LPCOLESTR pszCustomAttribute
)
{
    HRESULT hr = S_FALSE;
    CComPtr<IMetaDataImport> pMetadata;
    mdToken token = mdTokenNil;
    CComPtr<IDebugField> pField;
    CComPtr<IDebugCustomAttributeQuery> pCA;

    ASSERT(IsValidWideStringPtr(pszCustomAttribute));

    METHOD_ENTRY( CDebugClassFieldSymbol::IsCustomAttributeDefined );

    IfFalseGo( pszCustomAttribute, E_INVALIDARG );

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

    IfFailGo( CDebugCustomAttribute::GetTokenFromAddress( m_spAddress, &token) );
    IfFailGo( pMetadata->GetCustomAttributeByName( token,
              pszCustomAttribute,
              NULL,
              NULL ) );
Error:

    METHOD_EXIT( CDebugClassFieldSymbol::IsCustomAttributeDefined, hr );

    if (hr != S_OK)
    {
        hr = S_FALSE;
    }

    return hr;
}

Zobacz też