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

  • Home
  • SEARCH
  • 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 234801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:12:52+00:00 2026-05-11T20:12:52+00:00

I am having a hard time with StyleCop rule SA1503 (CurlyBracketsMustNotBeOmitted). In my code

  • 0

I am having a hard time with StyleCop rule SA1503 (CurlyBracketsMustNotBeOmitted).

In my code I quite often have a pattern thus:

public void SomeFunction(string someArg)
{
    if (string.IsNullOrEmpty(someArg)) throw new ArgumentNullException("someArg");

    // rest of the function here
}

The rationale behind this is to save vertical space when doing multiple validation checks on a single argument and/or checks on many arguments. The logic in such a check is typically simple and concise and likewise for the exception that gets thrown.

However, I would never write

if (someConditional)
    DoSomeStuff();

I would always write

if (someConditional)
{
    DoSomeStuff();
}

So in summary:

  • Use curly brackets if the if statement is split across multiple lines
  • Don’t use curly brackets for simple argument validation etc that can be easily (and readably) put on one line

Can StyleCop help me here?

  • 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-05-11T20:12:53+00:00Added an answer on May 11, 2026 at 8:12 pm

    As already mentioned, unfortuntely StyleCop rules are either on or off and can’t be customised. It would be nice to have a simple way of customising rules but unfortunately you’ll need to write them from scratch.

    The way I’ve used StyleCop is to focus on using as many of the built in rules as possible and where I really have a fundamental issue with a rule (code documentation, for example), I just turn it off. I’m not concerned enough about the exceptions to go to the extent of writing custom rules.

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

Sidebar

Related Questions

I'm having hard time understanding the following C# code. This code was taken from
I'm having a hard time figuring out how to implement a factory pattern in
I having hard time understanding importance and benefits of Annotations and so have two
i am having hard time to fix my problem on VirtualStringTree. I have NodeData
I'm having hard time wrapping my head around this. I have an array called
In my code, I am having hard time to wrap text in last two
I've been having a hard time trying to understand PyPy's translation. It looks like
I'm having a hard time understanding and therefore managing arrays and indexes manually in
I'm having a hard time understanding some git/DCVS concepts. Here's what happened: I created
I'm having a hard time determining what characters must be escaped when using Perl's

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.