# Command\<T>

Namespace: **Wisej.Web**

Assembly: **Wisej.Framework** (4.0.0.0)

* [Command](https://docs.wisej.com/api/wisej.web/data-binding/wisej.web.command)
  * [Command\<T>](https://docs.wisej.com/api/wisej.web/data-binding/wisej.web.command-less-than-t-greater-than)

Implements the [ICommand](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommand) interface wrapping execute and canExecute actions.

{% tabs %}
{% tab title="C#" %}

```csharp
public class Command<T> : Command
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class Command(Of T)
    Inherits Command
```

{% endtab %}
{% endtabs %}

You can use this class to wrap custom commands to bind to controls that implement the [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource) interface and need to access the typed data source records. In the snippet below, the CommandDemoViewModel class derives from BindingList\<Customer> and allows the commands to directly interact with the typed [DataItem](https://docs.wisej.com/api/wisej.web/wisej.web.commandargs#dataitem) property.

```csharp

public CommandDemoViewModel : BindingList<Person>
{
  
  public Wisej.Web.ICommand SaveCommand { get; }
  
  public CommandDemoViewModel()
  {
    this.SaveCommand = new Command<Person>(
      execute: args => {
        DB.Save(args.DataItem);
      },
      canExecute: args => {
        return  args.DataItem.Name != null &&
            args.DataItem.Age > 0;
      });
  }
}

```

Now you can use data binding or a code assignment to connect the view model's Add command to a button's [Command](https://docs.wisej.com/api/buttons/wisej.web.buttonbase#command) property.

## Parameters

| Name  | Description                                 |
| ----- | ------------------------------------------- |
| **T** | The Type of the data passed to the actions. |

## Constructors

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Command(execute, canExecute)

Initializes a new [Command](https://docs.wisej.com/api/wisej.web/data-binding/wisej.web.command) wrapping an *execute* method and an *canExecute* method.

| Name           | Type                                                                                   | Description                                                                                                                                                           |
| -------------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **execute**    | [Action\<CommandArgs\<T>>](https://docs.microsoft.com/dotnet/api/system.action-1)      | Invoked by the [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource) to perform a command.                                       |
| **canExecute** | [Func\<CommandArgs\<T>, Boolean>](https://docs.microsoft.com/dotnet/api/system.func-2) | Invoked by the [ICommandSource](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommandsource) to determine whether it can execute the *execute* function. |

## Implements

| Name                                                                           | Description                                          |
| ------------------------------------------------------------------------------ | ---------------------------------------------------- |
| [ICommand](https://docs.wisej.com/api/wisej.web/interfaces/wisej.web.icommand) | Defines a command that can be used for data binding. |
