如何从 .cs 文件加载类 [英] How to load a class from a .cs file
问题描述
是否可以加载一个类并从它的 .cs
文件中创建它的实例?
Is it possible to load a class and create Instance of it from It's .cs
file?
我想在 .cs
文件中打开一个自定义类并在我的应用程序中创建它的实例
I want to open a custom class in a .cs
file and create instance of it in my application
谢谢
推荐答案
理论上是的 - 这主要取决于您是否拥有所有可用的依赖项...
in theory yes - it mainly depends on whether you have all dependencies available...
如果你可以使用内置的CSharpCodeProvider
将 .cs
- 文件编译为程序集(如果需要,可以纯粹在内存中),然后使用反射创建实例/使用类从那个程序集...
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:
- http://support.microsoft.com/kb/304655/en-us
- http://www.codeproject.com/KB/cs/codecompilation.aspx
- http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Compile-C-or-VB-source-code-run-time.html一个>
- http://www.c-sharpcorner.com/UploadFile/mgold/CodeDomCalculator08082005003253AM/CodeDomCalculator.aspx
- http://www.csharp-examples.net/reflection-examples/一个>
- http://csharp.net-tutorials.com/reflection/introduction/一个>
- http://www.codeproject.com/KB/cs/C__Reflection_Tutorial.aspx
- http://www.dotnetperls.com/reflection-field
- C# 反射:如何从字符串?
- http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx
- http://msdn.microsoft.com/en-us/library/system.type.aspx
这篇关于如何从 .cs 文件加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!