Preprocessor directives
-
Hello everyone, I've got a project and I am making a version 2 of this project. Though still version 1 must be active and used. So I'm using preprocessor directives to assign the extra parts for the program for version 2. But in this case I have to place a #define VERSION_2 in every file where I want to make a difference between version 1 and version 2. I would like to know if it is possible to put a #define in one file and use it in another file. For example:
//file test.cs
//#define VERSION_1
#define VERSION_2namespace Prog.test
{
class test
{
#if VERSION_1
doThat();
#elif VERSION_2
doAnother();
#endif
}
}//file chair.cs
namepace Prog.chair
{
class chair
{
#if VERSION_1 //does not work, because not defined
setHeight();
#elif VERSION_2 //does not work, because not defined
setWidth();
#endif
}
} -
Hello everyone, I've got a project and I am making a version 2 of this project. Though still version 1 must be active and used. So I'm using preprocessor directives to assign the extra parts for the program for version 2. But in this case I have to place a #define VERSION_2 in every file where I want to make a difference between version 1 and version 2. I would like to know if it is possible to put a #define in one file and use it in another file. For example:
//file test.cs
//#define VERSION_1
#define VERSION_2namespace Prog.test
{
class test
{
#if VERSION_1
doThat();
#elif VERSION_2
doAnother();
#endif
}
}//file chair.cs
namepace Prog.chair
{
class chair
{
#if VERSION_1 //does not work, because not defined
setHeight();
#elif VERSION_2 //does not work, because not defined
setWidth();
#endif
}
} -
You can define them in the project properties:
Project -> (Name) Properties -> Build -> Conditional compilation symbols
regards
-
Hello everyone, I've got a project and I am making a version 2 of this project. Though still version 1 must be active and used. So I'm using preprocessor directives to assign the extra parts for the program for version 2. But in this case I have to place a #define VERSION_2 in every file where I want to make a difference between version 1 and version 2. I would like to know if it is possible to put a #define in one file and use it in another file. For example:
//file test.cs
//#define VERSION_1
#define VERSION_2namespace Prog.test
{
class test
{
#if VERSION_1
doThat();
#elif VERSION_2
doAnother();
#endif
}
}//file chair.cs
namepace Prog.chair
{
class chair
{
#if VERSION_1 //does not work, because not defined
setHeight();
#elif VERSION_2 //does not work, because not defined
setWidth();
#endif
}
}I would think the best way to accomplish backwards compatibility is to derive a new class from the original, and then the calling assembly can use whichever version it wants. No need for compiler directives at all.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
I would think the best way to accomplish backwards compatibility is to derive a new class from the original, and then the calling assembly can use whichever version it wants. No need for compiler directives at all.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Why not using branches on a version control system (like SVN)? Sure, this makes things a bit complicated but should keep the code pretty clean. regards
- He's talking about making an assembly compatible between versions. Source control is completely out of context. 1) Just because you *can* make it more complex, doesn't mean you should.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001