標籤:
Assembly是一個包含來程式的名稱,版本號碼,自我描述,檔案關聯關係和檔案位置等資訊的一個集合。
可以通過Assembly的資訊來擷取程式的類,執行個體等編程需要用到的資訊。
建立NamespaceRef。
using System;using System.Collections.Generic;using System.Text;using System.Reflection;namespace NamespaceRef{ class Program { static void Main(string[] args) { Country cy; String assemblyName = @"NamespaceRef"; string strongClassName = @"NamespaceRef.Chinese"; // 注意:這裡類名必須為強類名 // assemblyName可以通過工程的AssemblyInfo.cs中找到 cy = (Country)Assembly.Load(assemblyName).CreateInstance(strongClassName); Console.WriteLine(cy.name); Console.ReadKey(); } } class Country { public string name; } class Chinese : Country { public Chinese() { name = "你好"; } } class America : Country { public America() { name = "Hello"; } }}可以根據名稱來建立指定的對象。這在為設計模式提供了方便。
http://www.cnblogs.com/muou/archive/2009/07/08/1518971.html
https://msdn.microsoft.com/zh-cn/library/system.reflection.assembly.aspx
C# Assembly