473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Dynamically creating a type at runtime.

I really, really want to store some settings somewhere that my control
utilizes to create new object(s)(i.e., class, struct) at runtime without it
knowing about the type it could create at compile time. The type would
support a particular interface or base class let's say.

Couple thoughts:

1. Store the 'serialized' data in the store and let the deserializer create
it for me.
Slower
2. Lookup table (but then my control needs to know all the types it could
create before compile time).
Would be faster than the serialized version.
3. ActiveX control
Here we would have the coclass lookup issue.
4. ?

There must be an easier way. How does the serializer instance the type from
data? I know it stores the class name in the stream but how does it go from
just the classname to the object instance?

Thx for the help.
Jun 27 '08 #1
3 4533
On Apr 17, 12:24*am, Psypher8 <Psyph...@discussions.microsoft.com>
wrote:
I really, really want to store some settings somewhere that my control
utilizes to create new object(s)(i.e., class, struct) at runtime without it
knowing about the type it could create at compile time. *The type would
support a particular interface or base class let's say.

Couple thoughts:

1. *Store the 'serialized' data in the store and let the deserializer create
it for me.
* * Slower
2. *Lookup table (but then my control needs to know all the types it could
create before compile time).
* * *Would be faster than the serialized version.
3. *ActiveX control
* * Here we would have the coclass lookup issue.
4. *?

There must be an easier way. *How does the serializer instance the type from
data? *I know it stores the class name in the stream but how does it go from
just the classname to the object instance?

Thx for the help.
Hi,

You need to provide more details, but you can always use an Object
reference and access all the members by reflection.
Another alternative that I eager you to explore is define an interface
and make that "dynamic" object you have implement it, in this case at
runtime you can use any type of object as long as it implements that
interface
Jun 27 '08 #2
Here's an example:

At runtime I load a string that identifies a type.
Example: "SomePackage.SomeFolder.SomeTypeObject"

I would like to create that type now.

I have tried utilizing the Assembly object but it only exposes types inside
that assembly which is nice but won't work in the case I'm developing.

Jun 27 '08 #3
Does Activator.CreateInstance come close? Note that you might need to
work the assembly-qualified names to get the best results.

Marc
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
1
by: Andy | last post by:
Can anyone tell me if it is possible to dynamically create generic collections? simply put I want to be able to something like this : public object test(SomeBaseClass param1) { if...
0
by: Tom | last post by:
Thanks Chris : However, during run time, it show error message "File / component cannot find " during run in Dim asm As =...
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
2
by: Smithers | last post by:
Using 3.5, I am stuck in attempting to: 1. Dynamically load an assembly 2. Instantiate a class from that assembly (the client code is in a different namespace than the namespace of the...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.