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 8350935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:28:25+00:00 2026-06-09T08:28:25+00:00

For ReSharper 6.1, there is no built-in inspection item for missing default statements within

  • 0

For ReSharper 6.1, there is no built-in inspection item for missing default statements within a switch for C#, however the custom patterns seem generally robust. I’ve messed around with them a bit for cases like missing else statements for if blocks, but I’m not sure how to do a check for missing default.

Here’s what I have so far:

Search Pattern

switch($expr$)
{
    case $val$:
        $statement$
        break;
    $missingDefault$
}

Replacement Pattern

switch($expr$)
{
    case $val$:
        $statement$
        break;
    default:
        break;
}

Where $expr$ is an expression, $val is an expression, $statement$ is any number of statements, and $missingDefault$ is a maximum of 0 statements.

The problems here are the following:

  • We can have any number of cases, which are themselves a collection made up of one or more statements (case + break, etc.) and any number of expressions
  • For search pattern matching, we should only match against occurrences where there is nothing after the last case (ie. no default)
  • We need the ‘break’ in the search pattern such that we can define nonexistence of statements thereafter. This break is required by the compiler, anyway.

Obviously, this search pattern only matches against occurrences containing a single case and no default, so is relatively useless. I need a pattern that will match against switches with any number of cases, any number of which may or may not contain a break (except the last case) and can contain any number of statements, and no default.

Thanks for your help.

  • 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-09T08:28:26+00:00Added an answer on June 9, 2026 at 8:28 am

    I’ve had a good crack at this and I don’t believe it is currently possible (Resharper 7)

    Having said that you can always ask on the Resharper forum

    The only thing I can provide that may be of any use is the pattern to find

    1) all switch statements

    switch($expr$)
        $statement$
    

    2) the switch statements that end in default; break:

    switch($expr$)
    {
        $statement$
        default:
        break;
    }
    

    You could then use the difference of these two lists to determine which ones are missing the default;break; statement. For example in my project I have 231 occurrences of the first and only 58 of the second.

    I realise this is a long way off what you wanted (no replace!) but its the best I can muster.

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

Sidebar

Related Questions

Is there any ReSharper/StyleCop-like Visual Studio addon for C/C++? I'm using ReSharper and StyleCop
Is there any way to indicate to ReSharper that a null reference won't occur
Is there a setting in ReSharper to automatically format single-statement IF statments with the
Is there a way to upgrade resharper 6.1.1 to use nunit 2.6 in the
Is there a keyboard shortcut in Visual Studio 2010 (I'm using ReSharper 6.1 also)
Resharper is showing a Possible System.NullReferenceException warning. I however can't see how I can
In ReSharper 4.x there was a shortcut (Ctrl+8) for turning off the code analysis
I am using Visual Studio 2008, and Resharper 5.0: There are certain keywords such
Is there a keyboard shortcut to display tooltips provided by Visual Studio & Resharper
I'm using Resharper 4.5 with Visual Studio 2008 and MBUnit testing, and there seems

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.