Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:02:56+00:00 2026-06-04T06:02:56+00:00

I have a brownfield application which has a complex method. The CC is 14.

  • 0

I have a brownfield application which has a complex method. The CC is 14. The if statements verify application settings and generate the appropriate inline SQL.

E.G. This if statement checks the settings. settings is custom code, a DTO with several bool (not bool?) properties.

        string conditions = " AND (";

        List<string> conditionStrings = new List<string>();

        if (settings.AlwaysIncludeCommonResults && settings.SelectedCommonLabs.Count > 0)
        {
            string common = " (Table.Name in (";
            for (int i = 0; i < settings.SelectedCommonLabs.Count; i++)
            {
                common += string.Format("'{0}'", settings.SelectedCommonLabs[i]);
                if (i < settings.SelectedCommonLabs.Count - 1)
                    common += ", ";
            }
            common += ")) ";
            conditionStrings.Add(common);
        }

        if (settings.AlwaysSelectLast24HoursResults)
        {
            string last24 = " (DateDiff(hh, Table.PerformedDtm, GetDate()) < 24) ";
            conditionStrings.Add(last24);
        }

I don’t know what to do to simplify this bool logic. Null coalesce?…I don’t know that it will make this any better. This pattern appears several more times in the same method. So I hope to reuse the answer several times to decrease overall CC and increase readability. What do you suggest?

UPDATED
After deciding to rip out the first verification, added further method logic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:02:57+00:00Added an answer on June 4, 2026 at 6:02 am

    I’d start by shrinking code a bit:

       string common = " (Table.Name in (";
                for (int i = 0; i < settings.SelectedCommonLabs.Count; i++)
                {
                    common += string.Format("'{0}'", settings.SelectedCommonLabs[i]);
                    if (i < settings.SelectedCommonLabs.Count - 1)
                        common += ", ";
                }
                common += ")) ";
                conditionStrings.Add(common);
    

    can be shrunk:

    string common = " (Table.Name in (";
    //if SelectedCommonLabs is a collection of strings, LINQ your way through it
    common += string.Join(", ", settings.SelectedCommonLabs.ToList().Select(lab => string.Format("'{0}'",lab)));
    common += ")) ";
    conditionStrings.Add(common);
    

    But I agree this is not very nice code to begin with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application which works with a legacy database (brownfield). I have
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a matrix report now that has Position, Hours and Wages for a location
Have converted devise new session from erb to Haml but doens't work, this is
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have a look at this url: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jquery_ui_methods#column_chooser I have got the Column Chooser dialog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.