c# - 从 DLL/程序集获取实例?

标签 c# dll

我得到了以下生成 DLL 的代码:

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、Timer、AnotherClass 和 Test),代码如下:

IEnumerable<Type> types = library.GetTypes();

但我认为这不是我获得 10 个实例的方式...

(ps:我什至不确定这 10 个实例是否包含在我的 DLL 文件中...)

最佳答案

你的问题没有任何意义。

这些实例仅在您执行 Main() 时存在。

如果 Main() 包含一个依赖于用户输入的循环,您希望得到什么?

关于c# - 从 DLL/程序集获取实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8011941/

相关文章:

c++ - 对 WSACleanup() 的错误调用杀死了 WSAStartup()

c# - 如何将桌面应用程序与网页连接?

c++ - std::ofstream 在 DLL 中的行为不同

c# - 如何使用 epplus 在 excel 中将小数格式化为百分比?

c# - 将重复的列表条目合并为一个并在 C# 中显示数量

delphi - 使用环境变量 "The program can' 进行调试时无法启动,因为 ....dll 丢失”

c# - 在 C# 中编码(marshal) C 数组

运行时的 C++ 编译

c# - 如何定义 'value'属性 setter 参数

c# - 给内部类对象赋值