Hello,
I created a dynamic object but I do not know how to use it when the instanciation of the object is finished.
I would like to call some methodes from Class Base by an objet that I created dynamically. Can you explain me, pls? Thank you
This is my code:
MAIN
static void Main(string[] args)
{
/*
* Electric
* Hydraulic
* Mechanic
*/
Object objObject;
Tools objTool = new Tools();
objObject = objTool.CreateInstance("Electric");
try
{
//objObject. ??? (how to call some methodes from Class Base ?)
}
catch(Exception)
{
}
Console.Read();
}
Class Base
class Base
{
public void setStarted()
{
Console.WriteLine("Started");
}
public void setStopped()
{
Console.WriteLine("Stopped");
}
public void setStoppedUrgently()
{
Console.WriteLine("Stopped Urgently");
}
}
Class Tools
class Tools:Base
{
public object CreateInstance(string sTypeName)
{
foreach (Assembly objAssembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (Type objType in objAssembly.GetTypes())
if ((sTypeName == objType.Name) || (sTypeName == objType.FullName))
{
return Activator.CreateInstance(objType);
}
return null;
}
}