I have a C# .NET Compact Framework 3.5 mobile project in Visual Studio 2008. The program uses a barcode scanner and works for two different types of Windows Mobile devices (both using their own SDK to manipulate the barcode scanner). How can I conditionally add the reference to the scanner SDK SDK DLL file? i.e., if compiling for HARDWARE1 configuration I don’t want to add a reference to HARDWARE2-SCANNER-SDK.DLL.
Share
You can specify which DLL(s) to load in your app.config file and then use the Assembly.Load method to load the proper library(libraries.)
That’s the simple answer. But to really make this work you might need to create a few “wrapper” assemblies that share a common API (also in a separate library) so that your final application will not have to care where your scanner info is coming from. It should be ignorant of what hardware is being used.
Btw: This is all related to the concept of dependency injection, albeit at the module rather than a class level. Here are a couple of resources to get you started:
http://msdn.microsoft.com/en-us/magazine/cc163739.aspx
http://en.wikipedia.org/wiki/Dependency_injection