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

Instantiating a class by variable?

I set up a global variable:
string DesiredString;

I set up an array of a struct:

struct structProcessClass
{
public string Name;
public Type Class;
}

I fill the array:
structProcessClass tempProcessClass;
Type[] MyTypes = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type thisType in MyTypes)
{
if (thisType.BaseType.ToString() == "ProcessTrackData.ProcessingClass")
{
tempProcessClass.Class = thisType;
tempProcessClass.Name = tempStringOut;
ProcessClasses.Add (tempProcessClass);
}
}

I determine which class I want and instantiate it:
DesiredString = cmbProcessingType.Text;
foreach (structProcessClass thisClass in ProcessClasses)
{
if (thisClass.Name == DesiredString)
{
object[] args = new object[4]{DBFFile, NumberOfRecords, fsr, sw};
DesiredClass =
(ProcessingClass)System.Activator.CreateInstance(t hisClass.Class, args);
break;
}
}

Later, I call a member of the desired class:
ExcludeRecord = DesiredClass.ProcessRecord(Fields, StopGet);

Now that you know what I am doing, I can ask my question. This seems to
work just as I expect it to on my machine. But, when I try it on another
machine (which also has framework installed), it never calls the constructor
for my DesiredClass. In other words, the statement
DesiredClass =
(ProcessingClass)System.Activator.CreateInstance(t hisClass.Class, args);
does not seem to work. Does anyone know why this does not work on another
machine and how to fix it? Does anyone know of another way to do it.

I do know that once I know the name of the class I can use either an 'if' or
'case' and put in specific calls. But, I would rather not do this because I
am continually creating new classes and I would have to modify the if/case
area each time I added a new class.
Nov 17 '05 #1
0 972

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

Similar topics

1
by: thechaosengine | last post by:
Hi everyone, I posted a question earlier about a collection class that I'd made seemingly getting instantiated magically after a class that contained a variable of that type had its constructor...
4
by: Stephen Corey | last post by:
I've got 2 classes in 2 seperate header files, but within the same namespace. If I use a line like: // This code is inside Class2's header file Class1 *newitem = new Class1(param1, param2); ...
9
by: Carl | last post by:
Hi, I have a class in .Net which I instantiate in my code behind on one of my aspx pages. When I am finished with the instance, what is teh best method of taking it out of memory. Should I...
2
by: HarishP | last post by:
Hi, How to avoid instantiating the class more than 10 times Harish.P Sr. Software Engineer Comat Technologies Pvt. Ltd., Bangalore Email: harish.p@comat.com
2
by: active | last post by:
Because of an example I followed I've been instantiating Image objects. Now I notice that the documentation says the Image class is an abstract base class. Things seem to be working! Is the...
6
by: Gary Frank | last post by:
What are the ramifications if I were to instantiate an object tens of thousands of times and add them to an array? Or hundreds of thousands of times? Do you know if the act of instantiating a...
3
by: Nagesh | last post by:
hi, I have seen the winvnc(tightvnc server) source code in this I seen that class member funtions are calling without instantiating the object i.e. like vncService::ShowDefaultProperties() where...
18
by: RB | last post by:
Hi guys (and gals!), I've got 2 classes, "TypesafeConstant" and "Color". "Color" inherits from "TypesafeConstant", and adds no new functionality. All "Color" does is to instantiate some class...
8
by: Snaggy | last post by:
Hi, this is my first day using c# and I must say it's cool but data types.. I'm not use to them (php...) they're driving me crazy. I need to declare a class variable, but I don't know it's type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.