Monday, 19 August 2013

Call method of unknow class type c#

Call method of unknow class type c#

Im trying to do something like this, but I don't know how and I'm kind of
lost
foreach ( var type in cmdTypes )
{
if ( type.Name.ToLowerInvariant() == Name.ToLowerInvariant() )
{
return (Commands)type.execute(cmdParams);//<==Incorrect
}
else
{
//Command not found!
return 1;
}
}
This class is a derived of Commands. This is the base class:
abstract class Commands
{
internal abstract int execute(object[] myParameters );
internal string Name;
public Commands()
{
Name=this.GetType().Name;
}
}
I want to be able to call the execute() for all classes that derive from
Commands How could I accomplish this?

No comments:

Post a Comment