How to load a class from a .cs file

11,622

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:

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

Share:
11,622
Arian
Author by

Arian

Please vote-up this thread: RDLC Report Viewer for Visual Studio 2022

Updated on July 18, 2022

Comments

  • Arian
    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 application

    thanks