PC Review


Reply
Thread Tools Rate Thread

Create Object from database stored class name

 
 
John Hughes
Guest
Posts: n/a
 
      20th Sep 2005
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?


 
Reply With Quote
 
 
 
 
Andrew Kirillov
Guest
Posts: n/a
 
      20th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>



 
Reply With Quote
 
shiv_koirala@yahoo.com
Guest
Posts: n/a
 
      20th Sep 2005
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an object from class TreeNode Ralf Microsoft Access Form Coding 3 18th Mar 2009 03:50 AM
Class Object -> XML -> Database??? Don Miller Microsoft ASP .NET 0 6th Feb 2007 02:23 PM
Serialization of class instance stored in database Mark Microsoft VB .NET 2 10th Jan 2005 03:38 PM
Create object by class name MuZZY Microsoft C# .NET 5 7th Sep 2004 12:18 AM
Re: Create object by class name Shell Microsoft C# .NET 0 6th Sep 2004 05:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:13 AM.