I am currently writing a helper library that connects to shop floor PLCs via Software Toolbox's TopServer.
The TopServer library has separate versions for x86 and x64 architectures and I want to load the appropriate version at runtime using late binding based on the CPU architecture of the calling code. The methods in the two libraries have the same signatures.
I can use reflection to load the relevant object using the below code but I am wondering what is the best method of using this instance in the calling code.
public class LateBinding
{
public static T GetInstance<T>(string dllPath, string fullyQualifiedClassName) where T : class
{
Assembly assembly = System.Reflection.Assembly.LoadFile(dllPath);
Type t = assembly.GetType(fullyQualifiedClassName);
return (T)Activator.CreateInstance(t);
}
}
As I'm late binding I don't get the types pre-runtime so was thinking that creating an interface based on the libraries method signatures would be a good way to implement both version.
Does anyone have a view on this method or recommendations on other methods?