IDebugGenericParamField::GetConstraints
이 제네릭 매개 변수와 연결된 제약 조건을 검색합니다.
구문
int GetConstraints(
uint cConstraints,
out IDebugField[] ppConstraints,
ref uint pcConstraints
);
매개 변수
cConstraints
[in] 제약 조건의 수입니다.
ppConstraints
[out] 이 필드와 연결된 제약 조건이 포함된 배열을 반환합니다.
pcConstraints
[in, out] ppConstraints
배열의 제약 조건 수입니다.
Return Value
성공하면 S_OK
를 반환하고, 실패하면 오류 코드를 반환합니다.
예시
다음 예제에서는 IDebugGenericParamField 인터페이스를 노출하는 CDebugGenericParamFieldType 개체에 대해 이 메서드를 구현하는 방법을 보여 줍니다.
HRESULT CDebugGenericParamFieldType::GetConstraints(
ULONG32 cConstraints,
IDebugField** ppConstraints,
ULONG32* pcConstraints)
{
HRESULT hr = S_OK;
CComPtr<IMetaDataImport> pMetadata;
CComPtr<IMetaDataImport2> pMetadata2;
mdGenericParamConstraint* rgParamConsts = NULL;
HCORENUM hEnum = 0;
ULONG cConst = 0;
ULONG iConst;
ULONG iConstOut = 0;
METHOD_ENTRY( CDebugGenericParamFieldType::GetConstraints );
IfFalseGo(ppConstraints && pcConstraints, E_INVALIDARG );
*pcConstraints = 0;
IfNullGo( rgParamConsts = new mdGenericParamConstraint[cConstraints], E_OUTOFMEMORY);
IfFailGo( m_spSH->GetMetadata( m_idModule, &pMetadata ) );
IfFailGo( pMetadata->QueryInterface(IID_IMetaDataImport2, (void**)&pMetadata2) );
IfFailGo( pMetadata2->EnumGenericParamConstraints( &hEnum,
m_tokParam,
rgParamConsts,
cConstraints,
&cConst) );
pMetadata->CloseEnum(hEnum);
hEnum = NULL;
for (iConst = 0; iConst < cConst; iConst++)
{
mdToken tokConst;
IfFailGo( pMetadata2->GetGenericParamConstraintProps( rgParamConsts[iConst],
NULL,
&tokConst ) );
switch (TypeFromToken(tokConst))
{
case mdtTypeRef:
{
Module_ID mid;
mdTypeDef tokClass;
IfFailGo( CDebugClassFieldType::GetClassToken(m_spSH, m_idModule, tokConst, &mid, &tokClass) );
IfFailGo( m_spSH->CreateClassType( mid, tokClass, ppConstraints + iConstOut ) );
iConstOut++;
break;
}
case mdtTypeDef:
{
IfFailGo( m_spSH->CreateClassType( m_idModule, tokConst, ppConstraints + iConstOut ) );
iConstOut++;
break;
}
case mdtTypeSpec:
{
PCCOR_SIGNATURE pvSig;
ULONG cbSig;
DWORD cb = 0;
DWORD dwElementType;
IfFailGo( pMetadata2->GetTypeSpecFromToken( tokConst, &pvSig, &cbSig) );
cb += CorSigUncompressData(&(pvSig[cb]), &dwElementType);
IfFailGo( m_spSH->CreateType( pvSig, cbSig, m_idModule, mdMethodDefNil, m_pGenScope, ppConstraints + iConstOut ) );
iConstOut++;
break;
}
default:
{
ASSERT(!"Bad constraint token");
}
}
}
*pcConstraints = iConstOut;
Error:
METHOD_EXIT( CDebugGenericParamFieldType::GetConstraints, hr );
DELETERG(rgParamConsts);
return hr;
}