0

I am in a situation where a method code implementation depends on the chosen Visual Studio solution configuration.

Each configuration targets a different external DLL that provides a different API version to allow me to differentiate them. These DLLs are for Autodesk Revit API if that information could help.

As you may think, each API version, although very similar, can have subtle differences between them forcing me to have different code depending on which version I am targeting.

I have defined different symbols (REVIT_2014, REVIT_2015, etc.) for each configuration knowing that I can rely on good old #ifdef directives but first I wanted to explore if there is a more elegant solution.

I have read about ConditionalAttribute but I cannot use it in the way I wanted, i.e.:

class Test
{
    [Conditional("REVIT_2015")]
    bool TestMethod
    {
        //Revit 2015 specific code
    }

    [Conditional("REVIT_2016")]
    bool TestMethod
    {
        //Revit 2016 specific code
    }
}

As ConditionalAttribute does not allow to override methods, nor it allows methods to return values.

Before I start plaguing my code with ugly #ifdef directives, is there any other solution I can look into?

Thanks in advance.

Super Rey
  • 375
  • 2
  • 11
  • This invariably works much, *much* better if you make this actual configuration. Like a setting that you can read back at runtime to decide what to do. So one binary can handle any version of Revit and you never have to fiddle with building the correct library and ensuring it matches the machine. Or just plain reading the Revit version back at runtime so no config is necessary at all. – Hans Passant Jun 20 '17 at 12:17
  • @HansPassant if I opt to use what you suggest, how I will deal linking to different DLLs from the same binary? I mean, 2017 API may have methods not available in 2016 API and I also have to take into consideration deprecated and obsolete methods along with methods that does not exist any more after a specific API version. – Super Rey Jun 20 '17 at 13:09

0 Answers0