Method that filters a list parameters based on different fields I have this code which is a callback for Filter in WPF ICollectionView. When I run code analysis, the cyclometic complexity is reported to be 11. I consider this line by line comparison gives a better readability. How can I improve the cyclomatic complexity or improve this code in general?

 private bool FilterLicenseList(object item)
 {
     var license = item as LicenseEntry;
     if (!string.IsNullOrEmpty(Filter.Firm) &amp;&amp; !license.Firm.Contains(Filter.Firm)) return false;
     if (!string.IsNullOrEmpty(Filter.RegistrationCode) &amp;&amp; !license.RegistrationCode.Contains(Filter.RegistrationCode)) return false;
     if (!string.IsNullOrEmpty(Filter.LicenseCode) &amp;&amp; !license.LicenseCode.Contains(Filter.LicenseCode)) return false;
     if (!string.IsNullOrEmpty(Filter.Branch) &amp;&amp; !license.Branch.Contains(Filter.Branch)) return false;
     if (Filter.Active != null &amp;&amp; license.Active != Filter.Active) return false;
     return true;
  }
Your code has lots of duplication. You can make it more readable:

private bool FilterLicenseList(object item)
{
    var license = item as LicenseEntry;
    return FilterString(Filter.Firm, license.Firm)
        &amp;&amp; FilterString(Filter.RegistrationCode, license.RegistrationCode)
        &amp;&amp; FilterString(Filter.LicenseCode, license.LicenseCode)
        &amp;&amp; FilterString(Filter.Branch, license.Branch)
        &amp;&amp; FilterBoolean(Filter.Active, license.Active);
}


All you need to do now is to implement the two helper methods FilterString and FilterBoolean.

I know that even the rewritten code is visually redundant since the field name appears twice in each line of code, but removing this would be more difficult. Compared to the original code I find the rewritten code much more readable, and there is no chance that in one of the lines an exclamation mark is missing, which would be pretty easy to overlook.