简体   繁体   English

不同版本的不同类型库

[英]Different type libraries for different versions

in my c# project I'm using a type library of an third party software to communicate that software. 在我的C#项目中,我使用的是第三方软件的类型库来传达该软件。 But when someone uses an older Version of the third party software then I have to load another type library (an older one) how can I handle this? 但是,当有人使用较旧版本的第三方软件时,我必须加载另一个类型库(一个较旧的类型库),该如何处理呢?

And the next thing is, that in the type library may be some changes so my actual code doesnt work (maybe!!) 接下来的事情是,在类型库中可能进行了一些更改,因此我的实际代码不起作用(也许!)

First of all, you should create an Interface, which wraps the functionality of your thirdparty library. 首先,您应该创建一个接口,其中包含第三方库的功能。 If you do so, you can have 2 implementations of that interface. 如果这样做,则可以具有该接口的2个实现。 One for each Version of the third party library. 第三方库的每个版本一个。

public interface IWrapThirdParty {
  void ThirdPartyMethodOne(); 
  int ThirdPartyMethodTwo();
}

 public class ThirdPartyV1Wrapper : IWrapThirdParty {
  public void ThirdPartyMethodOne() {
    ThirdPartyV1 obj = new ThirdPartyV1();
    obj.ThirdPartyMethodOne();
  }
  public int ThirdPartyMethodTwo(){
    ThirdPartyV1 obj = new ThirdPartyV1();
    return obj.ThirdPartyMethodTwo();
  }
}

To solve your problem with loading the libraries: 要解决加载库的问题:

You can use the Assembly.Load() method after u figured out, which Version u want to load. 在确定了要加载的版本之后,可以使用Assembly.Load()方法。 But be aware to NEVER load an assembly 2 times. 但是请注意,切勿将装配件加载两次。

https://msdn.microsoft.com/en-us/library/system.reflection.assembly.load(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.reflection.assembly.load(v=vs.110).aspx


To check if the assembly is allready loaded u can use the AppDomain.CurrentDomain.GetAssemblies() Method, which will return all assemblies that are currently loaded into the AppDomain. 要检查程序集是否已全部加载,可以使用AppDomain.CurrentDomain.GetAssemblies()方法,该方法将返回当前已加载到AppDomain中的所有程序集。

https://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加具有不同版本的库 - Adding libraries with different versions 在不同的CATIA版本上刷新的COM库 - COM libraries refreshing on different CATIA versions 如何处理需要不同版本程序集的两个库? - How to deal with two libraries that need different versions of an assembly? 反序列化:类型转换错误(不同版本) - Deserialization : type conversion error (different versions) 来自同一程序集不同版本的相同类型的类型转换 - Type conversion of identical types from different versions of same assembly 从同一库的不同版本返回类型转换 - Return type conversion from different versions of same library 在一个解决方案中针对第三方静态库 (Creo) 的不同版本(发行版)进行构建 - Building against different versions (releases) of third party static libraries (Creo) in one solution 第三方库引用不同版本的log4net.dll - 3rd party libraries refer to different versions of log4net.dll 解决具有不同版本的装配体 - Resolving an assemblies with different versions ASP.NET C#:具有不同类库的程序集,这些类库针对不同的.Net版本并在内部相互依赖 - ASP.NET C# :assembly with different class libraries which are targeting different .Net versions and are internally dependent on each other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM