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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:33:20+00:00 2026-05-27T00:33:20+00:00

Does C# have a not Conditional ( !Conditional , NotConditional , Conditional(!) ) attribute?

  • 0

Does C# have a not Conditional (!Conditional, NotConditional, Conditional(!)) attribute?


i know C# has a Conditional attribute:

[Conditional("ShowDebugString")]
public static void ShowDebugString(string s)
{
   ...
}

which is equivalent1 to:

public static void ShowDebugString(string s)
{
#if ShowDebugString
   ...
#endif
}

But in this case i want the inverse behavior (you have to specifically opt out):

public static void ShowDebugString(string s)
{
#if !RemoveSDS
   ...
#endif
}

Which leads me to try:

[!Conditional("RemoveSDS")]
public static void ShowDebugString(string s)
{
   ...
}

which doesn’t compile. And:

[Conditional("!RemoveSDS")]
public static void ShowDebugString(string s)
{
   ...
}

which doesn’t compile. And:

[NotConditional("RemoveSDS")]
public static void ShowDebugString(string s)
{
   ...
}

which doesn’t compile because it’s only wishful thinking.

1 Not true, but true enough. Don’t make me bring back the Nitpicker’s Corner.

  • 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-27T00:33:21+00:00Added an answer on May 27, 2026 at 12:33 am

    First, having the Conditional attribute is not equivalent to having #if inside the method. Consider:

    ShowDebugString(MethodThatTakesAges());
    

    With the real behaviour of ConditionalAttribute, MethodThatTakesAges doesn’t get called – the entire call including argument evaluation is removed from the compiler.

    Of course the other point is that it depends on the compile-time preprocessor symbols at the compile time of the caller, not of the method 🙂

    But no, I don’t believe there’s anything which does what you want here. I’ve just checked the C# spec section which deals with conditional methods and conditional attribute classes, and there’s nothing in there suggesting there’s any such mechanism.

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

Sidebar

Related Questions

I have exceptions created for every condition that my application does not expect. UserNameNotValidException
Does gettext have a way to warn me about strings that have not been
C++ does not have native support for lazy evaluation (as Haskell does). I'm wondering
TTreeNode does not have a Visible property, so the obvious option does not exist.
Since silverlight does not have any support for DataSets/DataTables, what would be the best
Microsoft J++ does not have a Double.parseDouble() method. How do I do this?
As python does not have concept of constants, would it be possible to raise
VB 6.0 does not have any global handler.To catch runtime errors,we need to add
So Google Analytics does not have an API that we can use to get
SQL Server Express does not have the Tasks -> Import Data option that other

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.