Skip to main content

Execute a command

Execute a command

You can specify and execute a command defined in an extension using the ExecuteCommand method of the IApplication object.

public void ExecuteCommand(ICommandContext c, ICommandParams p) 
{
//Specify the identifier of a command defined in another extension
var commandIdentifier = "Command.SayHello";

//Execute the command
c.App.ExecuteCommand(commandIdentifier);
}

Pass parameters to a command

You can pass parameters to a command.

public void ExecuteCommand(ICommandContext c, ICommandParams p) 
{
var commandIdentifier = "Command.SayHello";

ICommandParams commandParams = c.App.CreateCommandParams();
commandParams.AddParamWithName("modelName", "ABC");
commandParams.AddParamWithName("close",true);

//Execute the command
c.App.ExecuteCommand(commandIdentifier, commandParams);
}

For commands defined in other extensions, you can handle command parameters as follows:

public void SayHello(ICommandContext c, ICommandParams p) 
{
var modelName = p["modelName"];
var close = (bool)p["close"];

//...
}