簡體   English   中英

App.config <bindingRedirect/> 使用強名稱進行組裝,然后在C#中使用短名稱

[英]App.config <bindingRedirect/> for assembly with Strong Name and then use Short Name in C#

我認為Title對我要問的問題不是很有啟發性,因此有一個例子。

我有此方法,該方法接收System.Windows.Forms Control的名稱,然后返回類型。 (我需要使用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")

我不喜歡這種方法的外觀,因為擁有該字符串似乎很奇怪。

所以我想知道是否有可能在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>

簡稱,我的意思是這樣的:

Type.GetType("System.Windows.Forms." + name)

可能嗎?

  1. 獲取對該程序集的引用,例如Assembly WinForms = Assembly.LoadLoadWithPartialName(如果您不想在其中包含版本)。 注意 :如果您知道程序集已經加載,則可以獲取諸如typeof(Form)之類的引用。 部件

  2. 使用winForms。 GetType (“ System.Windows.Forms。” +名稱)

由於您可以從特定的程序集中查詢類型,因此不必提供完全限定的類型名稱(包括程序集容器)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM