473,320 Members | 2,083 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,320 software developers and data experts.

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 1348
That's where reflection comes in:

using System.Reflection;

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

Type classType = Type.GetType(className, false);
ConstructorInfo constructor = classType.GetConstructor(new Type[0]); //
Assuming you want to use the default constructor
object newInstance = constructor.Invoke(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.com> wrote in message
news:u%****************@TK2MSFTNGP15.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.CreateInstance()

"Sahil Malik" <co*****************@nospam.com> schrieb im Newsbeitrag
news:u#**************@TK2MSFTNGP15.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/
-> "Instanzieren 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**************@TK2MSFTNGP12.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/
-> "Instanzieren 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
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...
36
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
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...
7
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). ...
2
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...
1
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...
25
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....
4
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...
7
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...
14
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.