eval a String to have a type

  • Thread starter Thread starter Eva
  • Start date Start date
E

Eva

Hi,

My problem is about I have a class name in a string
variable and I need create objects for that class. ¿How am
I able to use the string variable for it?

I have another problem. The class in the first problem is
a form that I'm try to open. The form is created
externally by the user (so isn't in my project) ¿Is
possible to use it without convert the .cs file in a DLL?

Thanks a lot,
Eva.
 
Eva said:
My problem is about I have a class name in a string
variable and I need create objects for that class. ¿How am
I able to use the string variable for it?

See Activator.CreateInstance, or if you need to call a specific
constructor, you can use Type.GetType() and then get the specific
constructor and invoke it.
I have another problem. The class in the first problem is
a form that I'm try to open. The form is created
externally by the user (so isn't in my project) ¿Is
possible to use it without convert the .cs file in a DLL?

Yes - have a class library project instead of an application. In this
case you'll need to load the assembly and then use Assembly.GetType
instead of just Type.GetType.
 
Back
Top