473,771 Members | 2,394 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 1590
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
1094
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
3741
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
1395
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
1168
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
2542
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
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10102
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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
9910
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
8933
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...
0
6712
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
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.