Share via


IDebugGenericParamField::ConstraintCount

Retourne le nombre de contraintes associées à ce paramètre générique.

Syntaxe

int ConstraintCount(
    ref uint pcConst
);

Paramètres

pcConst
[in, out] Nombre de contraintes associées à ce champ.

Valeur de retour

En cas de réussite, retourne S_OK , sinon, retourne un code d'erreur.

Exemple

L’exemple suivant montre comment implémenter cette méthode pour un objet CDebugGenericParamFieldType qui expose l’interface IDebugGenericParamField .

HRESULT CDebugGenericParamFieldType::ConstraintCount(ULONG32* pcConst)
{
    HRESULT hr = S_OK;
    CComPtr<IMetaDataImport> pMetadata;
    CComPtr<IMetaDataImport2> pMetadata2;
    HCORENUM hEnum = 0;
    ULONG cConst = 0;

    METHOD_ENTRY( CDebugGenericParamFieldType::ConstraintCount );

    IfFalseGo(pcConst, E_INVALIDARG );
    *pcConst = 0;
    IfFailGo( m_spSH->GetMetadata( m_idModule, &pMetadata ) );
    IfFailGo( pMetadata->QueryInterface(IID_IMetaDataImport2, (void**)&pMetadata2) );
    IfFailGo( pMetadata2->EnumGenericParamConstraints( &hEnum,
              m_tokParam,
              NULL,
              0,
              &cConst) );
    IfFailGo( pMetadata->CountEnum(hEnum, &cConst) );
    pMetadata->CloseEnum(hEnum);
    hEnum = NULL;

    *pcConst = cConst;

Error:

    METHOD_EXIT( CDebugGenericParamFieldType::ConstraintCount, hr );
    return hr;
}

Voir aussi