eval a String to have a class for work

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 cannot to use Type.GetType because it returns a Type and
I'm not able to access to properties for really class.
I've search for how use Activator.CreateInstance but in
exemples System.Runtime.Remoting namespace is used and
this library isn´t supported for Framework.

I have another problem. The class in the first ask 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?
I don't know when forms will be created, so I can't
include them in assemblies on my project.

Thanks a lot,
Eva.
 
J

Jon Skeet [C# MVP]

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?

Use Activator.CreateInstance.
I cannot to use Type.GetType because it returns a Type and
I'm not able to access to properties for really class.
I've search for how use Activator.CreateInstance but in
exemples System.Runtime.Remoting namespace is used and
this library isn´t supported for Framework.

Do you mean the Compact Framework? You don't have to use remoting to
use Activator.CreateInstance.
I have another problem. The class in the first ask 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?
I don't know when forms will be created, so I can't
include them in assemblies on my project.

Sorry, could you rephrase all that? The user has written some code, but
hasn't compiled it? Or is it just in a different assembly? If so, load
the assembly with one of the many Assembly.Load* methods, and then call
Assembly.GetType to get the type. Then you can get the appropriate
constructor of the type and invoke the constructor to get an instance.
 
G

Guest

Hi,
In reference to second problem: I've making an application
than take users' XML files. These files contein a form
name. These forms (like XMLs) will be made form users in
sometime in future (after the application had been made).
Application must to take the name of form and show it for
take information than will be added in the first XML.

Thanks a lot,
Eva.
 
J

Jon Skeet [C# MVP]

In reference to second problem: I've making an application
than take users' XML files. These files contein a form
name. These forms (like XMLs) will be made form users in
sometime in future (after the application had been made).
Application must to take the name of form and show it for
take information than will be added in the first XML.

Sure - but will it already have been compiled into an assembly? Your
first post talked about .cs files, which implied that it might not have
been.
 
E

Eva

In first, forms don't be compiled but, if it's need, we
can to make users compile it.

Only other thing, in msdn documentation I found than
Activator.CreateInstance return an ObjectHandle object and
ObjectHandle is a class in System.Runtime.Remoting
namespace, so I cannot declare any ObjectHandle variable.
How can I use Activator.CreateInstance then?

I'm sorry about all my asks I start with .Net and C# a
week ago.
Thanks a lot,
Eva.
 
J

Jon Skeet [C# MVP]

Eva said:
In first, forms don't be compiled but, if it's need, we
can to make users compile it.

That would certainly make things easier.
Only other thing, in msdn documentation I found than
Activator.CreateInstance return an ObjectHandle object and
ObjectHandle is a class in System.Runtime.Remoting
namespace, so I cannot declare any ObjectHandle variable.
How can I use Activator.CreateInstance then?

No, most overloads of Activator.CreateInstance return object - there
are only a couple of overloads which return ObjectHandle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top