[英]App.config <bindingRedirect/> for assembly with Strong Name and then use Short Name in C#
I think Title is not very suggestive in what I meant to ask, so theres is an example. 我认为Title对我要问的问题不是很有启发性,因此有一个例子。
I have this method that receives a name of System.Windows.Forms Control and then returns the type. 我有此方法,该方法接收System.Windows.Forms Control的名称,然后返回类型。 (I need to use Version=2.0.0.0 of System.Windows.Forms)
(我需要使用System.Windows.Forms的Version = 2.0.0.0)
return Type.GetType("System.Windows.Forms." + name + ", System.Windows.Forms,Culture=neutral, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089")
I don't like the appearance of this method, it seems weird by having that string. 我不喜欢这种方法的外观,因为拥有该字符串似乎很奇怪。
So I was wondering if it is possible to specify System.Windows.Forms Assembly in App.config file and use some short name in c#? 所以我想知道是否有可能在App.config文件中指定System.Windows.Forms Assembly并在c#中使用一些短名称?
<dependentAssembly>
<assemblyIdentity name="System.Windows.Forms" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.0.0.0"/>
</dependentAssembly>
By Short Name I mean something like this: 简称,我的意思是这样的:
Type.GetType("System.Windows.Forms." + name)
Is it possible? 可能吗?
Get a reference to that assembly, like Assembly winForms = Assembly.Load or maybe LoadWithPartialName if you don't want to include a version in there. 获取对该程序集的引用,例如Assembly WinForms = Assembly.Load或LoadWithPartialName(如果您不想在其中包含版本)。 Note : if you know that assembly is already loaded, you can get a reference with something like typeof(Form).
注意 :如果您知道程序集已经加载,则可以获取诸如typeof(Form)之类的引用。 Assembly
部件
use winForms. 使用winForms。 GetType ("System.Windows.Forms." + name)
GetType (“ System.Windows.Forms。” +名称)
Since you're able to ask for the type from a particular assembly, you don't have to give a fully-qualified type name (including assembly container) 由于您可以从特定的程序集中查询类型,因此不必提供完全限定的类型名称(包括程序集容器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.