How to load a class from a .cs file
Solution 1
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:
- 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
Solution 2
You can use Microsoft.CSharp.CSharpCodeProvider
and System.CodeDom
to execute code at runtime, there is an article about this code project here and here
Arian
Please vote-up this thread: RDLC Report Viewer for Visual Studio 2022
Updated on July 18, 2022Comments
-
Arian almost 2 years
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 applicationthanks