473,322 Members | 1,408 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,322 software developers and data experts.

how to define a variable of a type that is in a string

Hello all,

Imagine that I have this:

string myType = "FormProducts"; // FormProducts is the product's
form...

then, I'd like to create a variable of type "FormProducts" (or other
type that is in a string)... it would be like this:

FormProducts variableName;

Does anyone know how can I get this?

Aug 16 '07 #1
2 1300
Fernas,

You can use the static CreateInstance method on the Activator class to
take a Type instance (which you can get through a call to the static GetType
method on the Type class) and then create an instance of your class.

However, it will be returned as an object, which you have to cast to an
interface, or base class that you can use. If you already have a reference
to the library that contains the type, then you could cast to an instance of
that, but then that defeats the purpose of making the call to CreateInstance
(unless you want to access an object through remoting).

Or, you could use reflection to make calls on the object if you know the
method names and parameter types, but don't have an interface/base class to
cast to.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Férnas" <ga*****@wideweb.com.brwrote in message
news:11**********************@r34g2000hsd.googlegr oups.com...
Hello all,

Imagine that I have this:

string myType = "FormProducts"; // FormProducts is the product's
form...

then, I'd like to create a variable of type "FormProducts" (or other
type that is in a string)... it would be like this:

FormProducts variableName;

Does anyone know how can I get this?

Aug 16 '07 #2
Why dont you keep all the type qualified name, name and version ?
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Férnas" wrote:
Hello all,

Imagine that I have this:

string myType = "FormProducts"; // FormProducts is the product's
form...

then, I'd like to create a variable of type "FormProducts" (or other
type that is in a string)... it would be like this:

FormProducts variableName;

Does anyone know how can I get this?

Aug 19 '07 #3

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

Similar topics

1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
4
by: oliver.lin | last post by:
In my simple test code, I tried to define my constructor outside of the class declaration headr file. The header file: file_handler.h ============================================================...
21
by: Angel Lopez | last post by:
Sorry if I am too naive, but this is my first post... I have a binary variable (it can contain either a 0 or a 1). Is there any way I can define a data type that uses only 1 bit. So far I have...
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
6
by: Kay | last post by:
Hi all, In vb6, I can define a custom type like this: Private Type uClient sName As String sMonday As Double sMondayHeadCnt As Integer End Type
9
by: blangela | last post by:
Can somepoint me to a good discussion on the pros and cons of using #define versus a constant variable in your C+ application? Thanks, Bob
5
by: suresh | last post by:
Hi, How to define a two dimensional array where each row is of type vector<map<string,int>>? My idea is, if "x" is such a variable, x is a vector where each cell of the vector is a...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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.