I am working on a project that requires parsing IFC files using xBim and I need support both Ifc2x3 and Ifc4. Most of the Ifc class names and their properties are same in Ifc2x3 and Ifc4, but in xBim's object model the same classes in Ifc2x3 and Ifc4 namespaces do not share a common base class or interface so I will have to write the same code twice. I mean, if I am writing a function that retreives the volume of the space, or something simple like that, I would have to write that once for Ifc2x3 version of IfcSpace and another time for Ifc4 version of IfcSpace.
I thought about using compile-time directives to decide which namespace to load, but I am not sure if that is a good idea. I know this is an odd request, but is there any other way I can avoid writing the same code twice ?
You should just be able to use the interfaces in the Xbim.Ifc4.Interfaces
namespace. These interfaces are common across Ifc2x3 and Ifc4 implementations for precisely this scenario.
The sample at the bottom of the Xbim Quick Start demonstrates this scenario of working across Ifc Schemas with a single code base. http://docs.xbim.net/quick-start.html