1
我得到了下面的代碼生成一個DLL:從DLL/Assembly獲取實例?
public class MyObject : DependencyObject
{
}
public class Timer : DependencyObject
{
}
public class AnotherClass
{
}
public class Test
{
public static void Main()
{
MyObject q1 = new MyObject();
MyObject q2 = new MyObject();
MyObject q3 = new MyObject();
MyObject q4 = new MyObject();
Timer t1 = new Timer();
Timer t2 = new Timer();
Timer t3 = new Timer();
AnotherClass a1 = new AnotherClass();
AnotherClass a2 = new AnotherClass();
AnotherClass a3 = new AnotherClass();
}
}
那麼我想從我的DLL文件中提取實例。下面是我得到的那一刻:
var library = Assembly.LoadFrom(libraryPath);
但後來,我還沒有有關如何提取我的10個實例(4個MyObjects,3個定時器& 3 AnotherClasses)任何想法。我設法得到的唯一的事情就是4類(爲MyObject,定時器,AnotherClass和測試)的代碼:
IEnumerable<Type> types = library.GetTypes();
,但我覺得這不是我會得到我的10個實例的方式......
(PS:我甚至不能確定的10個實例包含在我的DLL文件...)
你很混亂*類型*和*對象*。 Main()創建的對象被局部變量引用,你不能去它們。它們也不以任何方式與DLL相關聯,它們像其他任何對象一樣生活在垃圾收集堆中。程序集包含代碼,而不是數據。 –