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.