如何从 .cs 文件加载类
是否可以加载一个类并从它的 .cs
文件创建它的实例?
我想在 .cs
文件中打开自定义类并在我的应用程序中创建它的实例,
谢谢
Is it possible to load a class and create Instance of it from It's .cs
file?
I want to open a custom class in a .cs
file and create instance of it in my application
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
理论上是的 - 这主要取决于您是否拥有所有可用的依赖项...
如果这样您就可以使用内置的
CSharpCodeProvider
将.cs
文件编译为程序集(如果需要,可以纯粹在内存中)是)和然后使用反射创建一个实例/使用该程序集中的一个类...由于没有提供太多细节,我建议检查这些链接,如果出现一些问题,请返回详细问题:
in theory yes - it mainly depends on whether you have all dependencies available...
IF so you can use the built-in
CSharpCodeProvider
to compile the.cs
- file to an assembly (can be purely in-memory if need be) and then use Reflection to create an instance/use a class from that assembly...Since don't provide much detail I would suggest to checkout these links and come back with detail questions if some arrise:
您可以使用
Microsoft.CSharp.CSharpCodeProvider
和System.CodeDom
在运行时执行代码,有一篇关于此代码项目的文章 此处 和 此处You can use
Microsoft.CSharp.CSharpCodeProvider
andSystem.CodeDom
to execute code at runtime, there is an article about this code project here and here