473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

instaniate an instance "dynamicall y" at runtime

Let's say
class parent
class B : parent
class C : parent
....etc. (may add later......so I don't know how many classes will there...)

I wanna to let the user type in the class name and instaniate a new instance
e.g.
string userinput = "classB"

parent temp = new SOMEFUNCTION("c lassB");
I wanted to ask what can SOMEFUNCTION be???

the point is that I dont' want to do
if (userinput == "classA")
temp = new A();
else if (userinput =="classB")
temp = new B();
....etc.

but rather
temp = new SOMEFUNCTION(us erinput); // temp can be A or B or other...
Nov 15 '05 #1
1 1588
100
Hi Action,

You can use reflection to create the objects.
Assembly.Create Instance(string )

Anyway you have to know the name of the assembly where the type is defined
and this assembly has to be in memory already.

HTH
B\rgds
100
"Action" <ac************ ***@hotmail.com > wrote in message
news:ud******** ******@TK2MSFTN GP09.phx.gbl...
Let's say
class parent
class B : parent
class C : parent
...etc. (may add later......so I don't know how many classes will there...)
I wanna to let the user type in the class name and instaniate a new instance e.g.
string userinput = "classB"

parent temp = new SOMEFUNCTION("c lassB");
I wanted to ask what can SOMEFUNCTION be???

the point is that I dont' want to do
if (userinput == "classA")
temp = new A();
else if (userinput =="classB")
temp = new B();
...etc.

but rather
temp = new SOMEFUNCTION(us erinput); // temp can be A or B or other...

Nov 15 '05 #2

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

Similar topics

0
1093
by: tommy | last post by:
hello everybody, i haved read a few articles about, how to create controls in asp.net dynamically! i have tested it -- all works fine.... but....now it comes--> HOW create controls dynamically using a html-table.... i want to display dynamically on each row one button, and dont use datagrid.
3
3740
by: Ahmed Ayoub | last post by:
i forgot how to create Textboxes & Label Dynamically. Meaning, i want to make them .. initialize their position .. and view them and interact with them.
9
5449
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could be able to generate and compile the project on the enviroments where Visual Studio.Net is not installed. Thanks and Regards, Anubhav Jain MTS Persistent Systems Pvt. Ltd. Ph:+91 712 2226900(Off) Extn: 2431 Mob : 094231 07471
2
1394
by: loga123 | last post by:
Hi All, I am new to .net. I am creating a text box in a "button1" "click event" dynamically based on user input. Name of the text box and ID of the text box contro are set dynamically in the server side code. How can make this text box accessable in another "sub" or "button2" click event? Any help is greatly appreciated.' thanks
2
1685
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of products like this one: <!-- File: Products.xml --> ... <Product id="p1">
2
1167
by: mkadasi | last post by:
I am fresher. Please help me. I am having many user defined classes(40-50) and based on some event,I want to create an instance dynamically and access its methods. I dont want to use switch case or if else..... something like typecasting or getting a reference.Please send the demo code in asp.net
1
1574
by: komaladevi | last post by:
can any one help me in writing acode -"how to edit "edit item template" dynamically""
5
14573
by: akonsu | last post by:
hello, i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. so far i found a way to add methods on demand: class A(object) : def __getattr__(self, name) : if name == 'test' : def f() : return 'test'
7
2541
by: tb2500 | last post by:
Dear all, I have a problem where I need to re-use the same instance of several classes over and over in my application. Like collections classes. Is there a way, with reflection for example, of finding out at runtime if an instance of a class already exists and then using that instance? Or do I have to create Singleton's for each of those classes? Should I make a class that keeps track of all my other class instances? Is there...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.