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

Determine Object Type From Database

P: n/a
Dan
All,

I am working on an application that allows users to track
various items for various clients. For example Client A
may have an object Box where Client B has an object
Canister. When a user goes to enter a new object I would
like the application to determine what objects are
available based upon the client (easy enough) and when
they determine what object to enter the program would know
that it needed to instantiate an object of that type. For
example, the user selects Client A and object Box the
program would instantiate an object of type Box. I want to
avoid hardcoding this into the application so that way if
I need to add object of type Carton later on I can insert
that object into the database, distribute a DLL for that
object, and the program would be able to instantate
objects of the type canister.

Does anyone have any idea if this is possible to do and if
so how? Any suggesions would be greatly appreciated.
Thanks!
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sounds to me like the database is not a central issue in this problem.
Getting the name of the type from the db is pretty simple, and I'll guess
that is not what is puzzling you.

What you seem to be asking for, is a way to instantiate types, selecting the
implementation of the type dynamically, at runtime.
You can do this via the System.Activator.CreateInstance() method, or via
Reflection with the System.Type.CreateInstance()
Check the archives of this group for tips .

You'll probably want to use interfaces to construct your extensible object
model, and employ a Factory pattern.
eg,
http://www.superdotnet.com/Article.aspx?ArticleID=158

suggestion: google for "factory CreateInstance interface"

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m

"Dan" <dd*****@fnisolutions.com> wrote in message
news:14****************************@phx.gbl...
All,

I am working on an application that allows users to track
various items for various clients. For example Client A
may have an object Box where Client B has an object
Canister. When a user goes to enter a new object I would
like the application to determine what objects are
available based upon the client (easy enough) and when
they determine what object to enter the program would know
that it needed to instantiate an object of that type. For
example, the user selects Client A and object Box the
program would instantiate an object of type Box. I want to
avoid hardcoding this into the application so that way if
I need to add object of type Carton later on I can insert
that object into the database, distribute a DLL for that
object, and the program would be able to instantate
objects of the type canister.

Does anyone have any idea if this is possible to do and if
so how? Any suggesions would be greatly appreciated.
Thanks!

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.