[英]c# Third party Reference Update Cause Issues
I was wondering if you would help. 我想知道您是否会帮助您。
I have an app written in c# that uses a reference from IBM (cwbx). 我有一个用c#编写的应用程序,它使用来自IBM(cwbx)的引用。
Originally using v5 I called the function; 我最初使用v5调用了该函数;
var download = new DatabaseDownloadRequest
{
system = host,
UseCompression = true
};
download.AS400File.Name = tableNames;
tempFileName = Path.GetTempFileName();
fileDescriptionFile = Path.GetTempFileName();
download.PCFile.Name = tempFileName;
download.PCFile.FileType = delimiterType;
However, IBM in their wisdom have changed the function .PCFile to .pcFile, causing my app to break. 但是,IBM用他们的智慧将功能.PCFile更改为.pcFile,导致我的应用程序中断。
This would not be an issue if all users within my company used the latest version, but there will be a slow uptake on this, so I need to be able to use both. 如果我公司中的所有用户都使用最新版本,这将不是问题,但是对此的吸收会很慢,因此我需要能够同时使用这两个版本。
Is there any sort of function where I can upper or lower case the function that I need to use so that it will be the same, or can you think of any other way I can do this? 是否可以在某种形式的函数中使用大写或小写形式使用我所需要使用的函数,以使它们相同,或者您能想到我可以采用的其他任何方式?
Thanks, 谢谢,
Dave 戴夫
I'd recommend wrapping these calls into a class that you've created which accesses them using reflection. 我建议将这些调用包装到您创建的类中,该类使用反射访问它们。 I can't imagine any other approach is going to result in anything stable.
我无法想象任何其他方法都会导致任何稳定的结果。
I think using reflection is your best solution here. 我认为在这里使用反射是最好的解决方案。
Something like this should work with either version of the library: 无论哪种版本的库都可以使用类似的方法:
PropertyInfo pcFileProperty = download.GetType().GetProperty("PCFile");
if (pcFileProperty == null)
{
pcFileProperty = download.GetType().GetProperty("pcFile");
}
if (pcFileProperty != null)
{
PCFileType file = (PCFileType)pcFileProperty.GetValue(download, null);
file.Name = tempFileName;
file.FileType = delimiterType;
}
else
{
// Property not found - IBM has changed the API again?
// Throw an exception?
}
This may be a roundabout way of doing it, but I've tried the following with some dummy classes and it seems to work: 这可能是一种回旋的方式,但是我已经尝试了一些虚拟类进行以下操作,并且似乎可行:
If you set this up right, you can make your core project not have to reference the IBM assembly at all, and you'll be able to check for the exception only once when your application starts, and thereafter have everything run as normal. 如果设置正确,则可以使您的核心项目完全不必引用IBM程序集,并且在您的应用程序启动时只能检查一次异常,然后使所有内容正常运行。
To clarify, I have five projects: 为了澄清,我有五个项目:
Once I have built the solution, I can drop the "old" or "new" DLL into my output folder and my console app will repond accordingly next time I run it. 构建解决方案后,可以将“旧”或“新” DLL放到输出文件夹中,并且我的控制台应用程序将在下次运行时相应地做出响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.