Hello:
I have the following lines to run a class for updated. I would like to change the name at runtime. Can someone tell me how?
ClassUpdateTest UpdateClass;
UpdateClass = new ClassUpdateTest(m_EventStopThread, m_EventThreadStopped, this);
UpdateClass.Run();
The "ClassUpdateTest"... I woulod like to change at run time. I have the value of it in a variable called textBoxUpdate.Text.
Loading
GustavoPosted Apr 21, 2010, 6:52 PM
I have tried what has been suggested and its not working or I am doing something wrong. (99% Probably I am doing something wrong.).
Can someone tell me or show me some sample code on how I can resolve this issue.
GustavoPosted Apr 20, 2010, 7:01 PM
Need to read some documentation...LOL... OK, where is the documentation.
This is what I did:
I do have a:
using System.Reflection;
The code is:
//object myDynamicClass = Assembly.CreateInstance(ClassNameTextBox.Text);
object myDynamicClass = Assembly.CreateInstance(textBoxClassName.Text);
The error is:
An object reference is required for the non-static field, method, or property 'System.Reflection.Assembly.CreateInstance(string)'
Mahesh ChandPosted Apr 20, 2010, 6:45 PM
Let's say, you have a TextBox named ClassNameTextBox.
To create an instance the class that is entered in the TextBox, this is what you do.
object myDynamicClass = Assembly.CreateInstance(ClassNameTextBox.Text);
This code will create an object containing the instance of your class.
Now you can type cast to your class and do whatever you want.
GustavoPosted Apr 20, 2010, 6:28 PM
I looked at MSDN and could not find what I needed. Like I said before... there are so many articles in MSDN that its hard for me to find what I needed.
I just want to call a Class with the name that is saved/stotred in a TextBox. Sounds simple...LOL... BUT, what do I k now.
Sam HobbsPosted Apr 20, 2010, 6:24 PM
GustavoPosted Apr 20, 2010, 3:32 PM
Ok, I will look at MSDN for my answer.
Yes, Like you said, I want to get the class name from a TextBox.
Hope I can find a good sample on MSDN. MSDN has a lot of good stuff but at times, its hard to find samples.
Mahesh ChandPosted Apr 20, 2010, 2:38 PM
Search C# Corner and MSDN for Assembly class and learn about its members.
Cheers!
Sam HobbsPosted Apr 20, 2010, 2:34 PM
Is the data to be saved in the form?
GustavoPosted Apr 19, 2010, 11:39 PM
It was a typo... it was to be "I would like to do the same for a 'Class'."
Here is some pseudo code of what I am trying to do:
Class oClassToCall = (Class)oAssembly.CreateInstance(SelectedClass.ToString());
oClassToCall();
The variable: "SelectedClass" can be selected from somewhere... its just a variable value. It will be the name of the class that I want to run.
It like what I am doing with the Form ans would like to do it with a Class.
Sam HobbsPosted Apr 19, 2010, 2:08 PM
GustavoPosted Apr 18, 2010, 2:57 PM
Maybe what I am asking is semi-impossible.
Let me try to explain it a little different.
When I want to run/open window with a variable name: I would do the following:
Form oFormToOpen = (Form)oAssembly.CreateInstance("ICEPack." + NodeTag_0[0].ToString());
oFormToOpen.MdiParent = this;
oFormToOpen.Show();
The NodeTag_0[0].ToString()); is the variable string that has the form that I want to open.
I would like to do the sa,me for a 'Class'.
BTW: It took me a while to find out there was a posting. I am not being notified by email any more.
GustavoPosted Apr 18, 2010, 2:57 PM
Maybe what I am asking is semi-impossible.
Let me try to explain it a little different.
When I want to run/open window with a variable name: I would do the following:
Form oFormToOpen = (Form)oAssembly.CreateInstance("ICEPack." + NodeTag_0[0].ToString());
oFormToOpen.MdiParent = this;
oFormToOpen.Show();
The NodeTag_0[0].ToString()); is the variable string that has the form that I want to open.
I would like to do the save for a 'Class'.
BTW: It took me a while to find out there was a posting. I am not being notified by email any more.
Sam HobbsPosted Apr 17, 2010, 2:45 PM
One thing that is not clear is if the data is stored in the same table in a database or somewhere else. If somewhere else, then it is not clear if the fields are the same for everything.
GustavoPosted Apr 16, 2010, 7:02 PM
What I am trying to do is:
I will have a bunch of classes that will do my updates. I would like to load a dataGridView with them and then when I click on the one I want, I want to run it. Is that a bit clearer? LOL.
Sam HobbsPosted Apr 16, 2010, 6:22 PM