473,569 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4540
On Apr 17, 12:24*am, Psypher8 <Psyph...@discu ssions.microsof t.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.So meFolder.SomeTy peObject"

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.Creat eInstance 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
5958
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; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
1
1836
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 (param1.prop1 == "blah") { //logic to determine the type
0
310
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 = AppDomain.CurrentDomain.Load("D:\vb7Project\dynamicCall\prj01\prj01\bin\prj0 1.dll")
7
6764
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 = LoadOracleData(sql) '____Do amazing things
4
5044
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, websites, MSDN and was not able to find something that would help me understand and code. I might not be searching for the right words or phrases. ...
11
3759
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
4665
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 that I found inside of a string. Any ideas?
2
3095
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 dynamically loaded assembly) so far so good (per my code below)... but here is where I'm getting hung up: 3. Call methods of that type (see comments in my...
2
5097
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 = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.