By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,383 Members | 1,993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,383 IT Pros & Developers. It's quick & easy.

Create Object from database stored class name

P: n/a
Hi,

Is it possible to create an object from a stored (database,xml or variable)
name?

For instance I have 2 class names stored in my database. Depending on the
application settings I want to create an object based on the class name that
I store in the database.

Any ideas how to do this?
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello

Here is some code:
string str = "System.String";

object[] parameters = new object[] { 'h', 5 };

object o = System.Activator.CreateInstance( Type.GetType( str ),
parameters );

System.Diagnostics.Debug.WriteLine( o.GetType().ToString() + " = " +
o.ToString() );

Activator.CreateInstance() can create an instance of an object of specified
type. If your object has parameterless constructor, then you can skip
parameters specification.

The above sample will create a String object, using the next constructor
CString(char c, int count).
--
With best regards,
Andrew
http://www.codeproject.com/script/pr...asp?id=1181072
"John Hughes" <jh******@msn.com> wrote in message
news:eN**************@TK2MSFTNGP15.phx.gbl...
Hi,

Is it possible to create an object from a stored (database,xml or
variable) name?

For instance I have 2 class names stored in my database. Depending on the
application settings I want to create an object based on the class name
that I store in the database.

Any ideas how to do this?

Nov 17 '05 #2

P: n/a
Tried reflection....Do not know if i have understood your statement
fully

Regards,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.