How can I SetType()?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an file from which I retrieve a type name. (i do not know what the
object type will be).

For argument's sake, the string data retrieved is
"System.Data.SqlClient.SqlParameter"

How can I create an object of type System.Data.SqlClient.SqlParameter from
this string, without prior knowledge of what the string says.

I have looked for a kind of SetType() method but can't find one.

Any help much appreciated.

CR
 
CodeRazor said:
I have an file from which I retrieve a type name. (i do not know what the
object type will be).

For argument's sake, the string data retrieved is
"System.Data.SqlClient.SqlParameter"

How can I create an object of type System.Data.SqlClient.SqlParameter from
this string, without prior knowledge of what the string says.

I have looked for a kind of SetType() method but can't find one.

Have a look at Type.GetType and Activator.CreateInstance.

Jon
 
thanks, I've been looking at both Type.GetType() and
Activator.CreateInstance(), but I'm having trouble using them to create the
final object.

Could you provide a short example.
So e.g. if my file has "System.Data.SqlClient.SqlParameter", how can I
create a System.Data.SqlClient.SqlParameter object from it. ?

thank you, CR
 
Hi,

What kind of trouble?

FYI, all the CreateInstance methods that receive a string needs to know the
assembly where that type is declared.. Do you know where are declared the
types you want to instantiate?
 

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

Back
Top