You may know this already. But I mention this anyway.
Use Platform-Specific Visual Studio Project File:
I use one Visual Studio Solution file. And then I use a separated Visual Studio project file for each platform (like CAMduct 2019, CADmep 2019, CADmep 2021, Revit 2021, Revit 2022, Revit 2022). Then I can assign platform specific source code files to each Visual Studio project file. This largely isolates platform specific things to each project.
Use Preprocessor Variables:
Sometime a source code file is being used in multiple platforms because by and large it is compatible to all those platforms. But there are some minor differences that I need to take care of (may be the API syntax or a property name is different from one platform to the other platform). In that case, I use preprocessor variable like this to account for the difference:
#if ( RVT2021 || RVT2022 )
...
#elif ( RVT2023 || RVT2024 )
...
#endif
And then define those preprocessor variables in Project Properties of the Visual Studio Project file.
Use Virtual/Derived Class:
Using preprocessor variable is not the only way to account for the difference. I also use a virtual class as an umbrella class to hide the difference. And then implement the platform specific stuff in the derived classes. Then the calling program only needs to deal with the interface of the virtual class.
Use Platform-Specific Member Variables:
Using derived classes is not the only way to hide the difference. I also use an umbrella class that has platform specific stuffs hidden in its member variables:
class CUnifiedUI
{
private int fUseUIType = 1; // 1 for UI-Type-1, 2 for UI-Type-2.
private CUIType1 uiType1 = null; // Specific to a platform.
private CUIType2 uiType2 = null; // Specific to other platforms.
public void SetToUseUIType1()
{
this.fUseUIType = 1;
}
public void SetToUseUIType2()
{
this.fUseUIType = 2;
}
public void DoSomething()
{
if ( this.fUseUIType == 1 ) this.uiType1.DoSomething();
else if ( this.fUseUIType == 2 ) this.uiType2.DoSomething();
}
}
I don't remember exactly why I have to use this last method. But I use this to deal with the difference in user interface between CAMduct and CADmep (and later Revit). For example, we can show message in the command line in CADmep, but the command line window is not available in CAMduct (or Revit).
I find that I need to use all 4 methods to deal with the different platforms. Some may work better than the others.
JC_BL