[我已經張貼一些非常相似,但這個問題並不好,這裏是我真的想知道]從DLL/Assembly獲取實例?
我得到了下面的代碼生成一個DLL:
public class MyObject : DependencyObject
{
}
public class Timer : DependencyObject
{
}
public class AnotherClass
{
}
public class Test
{
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文件...)
你不能只是在消費項目中引用你的DLL,然後像使用任何其他類庫一樣使用它嗎? –
Nop,我可以,因爲我會動態加載任何DLL在一個特定的文件夾:/ –
是否有一個具體的原因,你這樣做,而不是包括DLL爲您的項目的一部分? –