如何从.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
p>
推荐答案
在理论上是 - 它主要取决于你是否有所有的依赖关系...
in theory yes - it mainly depends on whether you have all dependencies available...
如果您可以使用内置的 CSharpCodeProvider
将 .cs
- 文件编译成一个程序集(如果需要可以完全在内存中),然后使用Reflection从该程序集创建一个实例/使用一个类...
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/ li>
- http://csharp.net-tutorials.com/reflection/introduction/
- http://www.codeproject.com/KB/cs /C__Reflection_Tutorial.aspx
- http://www.dotnetperls.com/reflection
- http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx
- < a href =http://msdn.microsoft.com/en-us/library/system.type.aspx> http://msdn.microsoft.com/en-us/library/system.type.aspx a>
- 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# Reflection: How to get class reference from string?
- http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx
- http://msdn.microsoft.com/en-us/library/system.type.aspx
这篇关于如何从.cs文件加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!