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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:59:58+00:00 2026-05-16T11:59:58+00:00

Say you have some boiler plate using statements. Say something like this: #if !NUNIT

  • 0

Say you have some boiler plate using statements. Say something like this:

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestContext = System.Object;
#endif

(This is for my unit testing code) If I did not want to put that in the top of every file that has unit tests, is there a way to setup a level of indirection here?

I don’t think this would work, but here is an example of what I am thinking of:

Make a file called NUnitCompatability.cs and put the above code in it. Then add using NUnitCompatability to all my unit test files. This would work in Delphi, but not in C# (I think). But is there another way to get to this type of functionality?

  • 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-16T11:59:59+00:00Added an answer on May 16, 2026 at 11:59 am

    No, this is not possible.

    You are probably thinking of using directives as if they were similar to an #include in C. This is not the case.

    A using directive only tells the compiler in which namespaces to search for the types used in a specific file. Therefore you are also not able to store them in a separate file.

    I wouldn’t bother to put conditional compiler directives in my code for using directives. There is almost no overhead related to unused usings at compile time (the search space is slightly larger) and no overhead at all at runtime.

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

Sidebar

Related Questions

Let's say I have some code (using CherryPy) that looks like this: import cherrypy
Say I have some django models, something like this: class Address(models.Model): pass class Person(models.Model):
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
Say I have some data like this: number_stream = [0,0,0,7,8,0,0,2,5,6,10,11,10,13,5,0,1,0,...] I want to process
Say I have some Scala code like this: // Outputs 1, 4, 9, 16,
Say I have some code like this function Chart(start, end, controller, method, chart) {
Say i have some rules and actions, like so , { do something; }
Say I have some situation like this: class Vertex { public: Position position; Normal
Say I have some structs like this: struct A{ int someInt; } struct B
Lets say I have some XAML like this: <StackPanel> <TextBlock Text=Blah Blah Blah />

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.