i’m fairly new to C# / .NET so I hope there is a solution for my problem.
I’m working with 2 different image-processing libraries which have their own classes to represent images. Because I don’t want to use this classes in my own (private) class library, I want to implement my own “myImage”-Class which is supposed to be a wrapper around both of the other classes. (I have of course to add the functionality of the libraries if they are missing).
My problem is basically now like this: The myImage-class needs a reference to both libraries to compile, however i sometimes would like to use the myImage-class in projects where only one library is available. I find it not difficult to “add” or “remove” references to my image class project, however i don’t want to comment out the code which refers to the missing library.
So my question is: is it somehow possible to determine wether a reference is set with a preprocessing directive or with attributes or with code directly? Or is there even a better solution for my problem (a clever class design maybe?)
Thanks for the help
I don’t think there’s a preprocessor directive that will tell you if a reference has been added.
You could always split your class into two separate classes, one for each library, but I suspect your intention was to join the two into one unified class.
What I would do is use 2 conditional compilation symbols (see Properties | Build), one for methods specific to the first library, the other for the second library. Whenever the class’s code refers to data members or functions specific the the library, it would be surrounded by a #if directive, referring to the appropriate symbol.
If your intention was not to join the classes, Reed’s and Daniel’s solutions are probably more appropriate.