10

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,795
  • 60
  • 169
  • 277

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
  • 68,257
  • 8
  • 107
  • 138
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,189
  • 7
  • 48
  • 74