11

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

Arian
  • 12,793
  • 66
  • 176
  • 300

2 Answers2

13

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:

Community
  • 1
  • 1
Yahia
  • 69,653
  • 9
  • 115
  • 144
4

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

Vamsi
  • 4,237
  • 7
  • 49
  • 74