Hello Everyone,
There is one function in c# for console application where our company went for sonar qube scan and it resulted cognitive complexity of 23 to 15.
Can you please provide me any solution to decrease the complexity to avoid more loops, if conditions and continue statements.
private void ChildPopulateAssetSettlementHash1(ArrayList lstFieldsAHV, Hashtable fieldPositionsHash_AHV, string agreementId, string securityID, Hashtable AHV_Hash)
{
foreach (string[] fields_AHV in lstFieldsAHV)
{
if (fieldPositionsHash_AHV.Contains("Region"))
{
string aRegion = fields_AHV[(int)fieldPositionsHash_AHV["Region"]];
bool isRegionSkip = IsRegionSkip(aRegion);
if (isRegionSkip)
continue;
}
string agreementID = fields_AHV[(int)fieldPositionsHash_AHV["Agreement Ext Id"]];
string instrumentID = fields_AHV[(int)fieldPositionsHash_AHV["Instrument ID"]];
if (agreementID.Equals(agreementId) && securityID.Equals(instrumentID))
{
if (AHV_HASH.ContainsKey(agreementId) && !(((Hashtable)AHV_Hash[agreementId]).ContainsKey(instrumentID)))
{
((Hashtable)AHV_Hash[agreementID])[instrumentID] = fields_AHV;
}
else if (AHV_Hash.ContainsKey(agreementId))
{
continue;
}
else
{
AHV_Hash[agreementId] = new Hashtable();
((Hashtable)AHV_Hash[agreementId])[instrumentID] = fields_AHV;
}
if (agreementID.Equals(agreementId) && !securityID.Equals(instrumentID))
{
if (AHV_HASH.ContainsKey(agreementId) && !(((Hashtable)AHV_Hash[agreementId]).ContainsKey(securityID)))
{
((Hashtable)AHV_Hash[agreementID])[securityID] = fields_AHV;
}
else if (AHV_Hash.ContainsKey(agreementId))
{
continue;
}
else
{
AHV_Hash[agreementId] = new Hashtable();
((Hashtable)AHV_Hash[agreementId])[instrumentID] = fields_AHV;
}
}
}
}
}