473,566 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is this possible to do?

Lets say .. I get a string ..
"System.Windows .Forms.TextBox"

Can I instantiate an instance of that .. given that the ONLY information I
have is that string above i.e. classname?

To make things easy, such a classname is in GAC.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/


Nov 16 '05 #1
4 1364
That's where reflection comes in:

using System.Reflecti on;

string className = "System.Windows .Forms.TextBox" ;

Type classType = Type.GetType(cl assName, false);
ConstructorInfo constructor = classType.GetCo nstructor(new Type[0]); //
Assuming you want to use the default constructor
object newInstance = constructor.Inv oke(new object[0]); // Again assuming
you're using the default constructor

Now you can cst newInstance to the required object to access the methods /
properties you need.

Hope this helps.

Jako Menkveld

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:u%******** ********@TK2MSF TNGP15.phx.gbl. ..
Lets say .. I get a string ..
"System.Windows .Forms.TextBox"

Can I instantiate an instance of that .. given that the ONLY information I
have is that string above i.e. classname?

To make things easy, such a classname is in GAC.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

Nov 16 '05 #2
You can also use Activator.Creat eInstance()

"Sahil Malik" <co************ *****@nospam.co m> schrieb im Newsbeitrag
news:u#******** ******@TK2MSFTN GP15.phx.gbl...
Lets say .. I get a string ..
"System.Windows .Forms.TextBox"

Can I instantiate an instance of that .. given that the ONLY information I
have is that string above i.e. classname?

To make things easy, such a classname is in GAC.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

Nov 16 '05 #3
Sahil,

In my idea is the newsgroup language.vb the last half year full of your
question.

One of the answers (Not mine this is German not Dutch)

http://www.mvps.org/dotnet/dotnet/code/codingtechnique/
-> "Instanzier en anhand des Klassennamens"

Cor
Nov 16 '05 #4
Thanks Cor .. I can make do with both German and Dutch .. so the link is
useful.
Thanks Jako,
Thanks cody.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:#A******** ******@TK2MSFTN GP12.phx.gbl...
Sahil,

In my idea is the newsgroup language.vb the last half year full of your
question.

One of the answers (Not mine this is German not Dutch)

http://www.mvps.org/dotnet/dotnet/code/codingtechnique/
-> "Instanzier en anhand des Klassennamens"

Cor

Nov 16 '05 #5

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

Similar topics

4
14463
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping not to have it inserted or read from a database to do this function. Can it be done & someone please help me?
36
9442
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
20
2454
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to the site, and then i have to select the file to upload.. i used sendkeys.. and i worked perfect.. BUT ... the computer must be locked for security (...
7
2338
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). After some time, I added new function void f4(void).
2
3796
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens provide text area where the user can insert big chunks of text and submit it all to the server paragraph by paragraph. The requirement is to do a...
1
6949
by: AAA | last post by:
hi, I'll explain fastly the program that i'm doing.. the computer asks me to enter the cardinal of a set X ( called "dimX" type integer)where X is a table of one dimension and then to fill it with numbers X; then the computer asks me how many subsets i have (nb_subset type (integer)) then,i have to enter for every sebset the card, and then...
25
2530
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do. The problem is that refreshing evry n seconds has...
4
7655
by: RSH | last post by:
Okay my math skills aren't waht they used to be... With that being said what Im trying to do is create a matrix that given x number of columns, and y number of possible values i want to generate a two dimensional array of all possible combinations of values. A simple example: 2 - columns and 2 possible values would generate: 0 0
7
3349
by: Robert S. | last post by:
Searching some time now for documents on this but still did not find anything about it: Is it possible to replace the entry screen of MS Office Access 2007 - that one presenting that default 'templates' (with that big graphic buttons) - with some sort of own HTML-Page? I could imagine, that somehow it is possible to change this construction...
14
1991
by: bjorklund.emil | last post by:
Hello pythonistas. I'm a newbie to pretty much both programming and Python. I have a task that involves writing a test script for every possible combination of preference settings for a software I'm testing. I figured that this was something that a script could probably do pretty easily, given all the various possibilites. I started...
0
7673
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...
0
7584
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...
0
7893
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
8109
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
7645
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
7953
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...
0
3643
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
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
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

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.