Please help me understand this stuff.  I am missing something
important...  If anyone knows of a good reference/description of the
type system, I'd really appreciate a link.

Here is my problem:

I have a system where I have a base class (called Profile) that knows
how to store itself in the database.  It stores its data in the database
and its Assembly Qualified Type Name.  At runtime I am reading the
Assembly Qualified Type Name and using Activator.CreateInstance to
create the object in memory.  I use this system because derived types
may not be located in an assembly that I have access to at compile-time.
This works fine except that I need to require a certain type of
constructor to be available to know how to construct the objects (there
are certain data requirements that necessitate the need for a certain
style of constructor).  So I would like to do one of two things (neither
of which I can get to work yet):

1. Specify in my base class that a constructor style is required (like
marking it abstract, but C# doesn't support this of course)
.or.
2. Create objects of the Type of my base class and at runtime, up-cast
them to the new type.

The nature of these objects is that the base class holds data structures
that actually hold all the data for derived classes so I don't need to
worry so much about an up-casting needing more memory allocated (since
in the usual case the derived class may be larger in memory than the
base class).  I like option #1 as it is a lot more clean, but I just
hate the idea that I can only assert this at runtime.  If I could get
derived classes to get a compiler error or warning if they didn't
implement the required constructor, I'd be all set.

Ideas?

Thanks,

Shawn Wildermuth
[EMAIL PROTECTED]
http://adoguy.com
http://shawnwildermuth.com

"...for the programmer, as for the chef, the urgency of the patron may
govern the scheduled completion of the task, but it cannot govern the
actual completion. An omelette, promised in two minutes, may appear to
be progressing nicely. But when it has not set in two minutes, the
customer has two choices--wait or eat it raw. Software customers have
had the same choices. The cook has another choice; he can turn up the
heat. The result is often an omelette nothing can save--burned in one
part, raw in another.... " - Brooks, The Mythical Man-Month.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to