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
CS files may be opened and edited with basic text editors, including Microsoft Notepad++ (bundled with Windows) or Apple TextEdit (bundled with macOS). However, plain text editors are not good options for editing the files since they do not support the syntax structure.
What is a CS file? Files with . cs extension are source code files for C# programming language. Introduced by Microsoft for use with the . NET Framework, the file format provides the low-level programming language for writing code that is compiled to generate the final output file in the form of EXE or a DLL.
It is easier to: Run Visual studio -> Make a new C# console project. This makes a project with a simple Program. cs file. You can just copy/paste in that, and run the project my clicking F5.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With