I want to be able to write a function which uses code from a library (lets call it libx) without having to change the code around depending on which version of libx I am using.
For example
public string ReturnFormattedString(string input) {
//If using version 1 of library
return libx.SomeClass.FormatString(input);
//If using version 1 of library
//If using version 2 of library
return libx.SomeNewClass.FormatString(intput);
//Note: libx.SomeNewClass is not available in version 1
//If using version 2 of library
}
I am not even sure if this is possible, but I would like to know how such a thing could be achieved, so that I could be able to compile my code without having to do any changes depending on which version of libx is in use.
Edit:
Just to clear some things up. I do not have access to the code of libx. My application is a plugin that works on top of another program which uses libx. So the version of libx depends on the version of the program I am plugging into.
I'm starting to think this might not be possible without having two different assemblies each with a different implementation of ReturnFormattedString according to which version of libx I am targeting (which is what I wanted to avoid in the first place).