We help IT Professionals succeed at work.

Conditional compilation: I want to compile functions on the basis of knowing or not knowing the type of the parameter value (without using /d or /define). Like #ifdef __XYZ_H__ in C++...

Fleasoft
Fleasoft asked
on
Medium Priority
414 Views
Last Modified: 2011-09-20
I'd like to build a class (Abc) that is shared between C# projects on source code basis. Some of these projects know a particular class (Xyz), some don't.
So when I make a function like Abc.DoSomething(Xyz xyz), it would result in a compile time error in the projects where Xyz is not known. How can I make source code that is only compiled when Xyz is known?
#define works only within the same source file and I'd like to avoid others to need more than including the source file of Abc to their project.

regards, Flea
(Don't beat me, if my English is too poor for you.)

P.S.: At least, there would be the possibility to make a #if ... #warning section...
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Okay, the solution of TheAvenger (thanks for contribution) was still known to me but I've searched for an easier to apply solution (see the sentence beginning with #define), where the programmer sharing the code file to his/her project has little effort to do. So perhaps there's a way to automatically add the define to project properties?
I don't think so :-(( Unforutnately the preprocessor of C# is not so powerful as it is in C++....

Author

Commented:
Unfortunately I'm afraid I'll have to agree you :-(( They should have been thought on something like that.
Thanks anyway...

regards, Flea
As TheAvenger points out all the developer has to do is add the def to the "Conditional Compilation Section" in the projects properties...... it difficult to see how much easier it could be...
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.