# Command\<T>

Namespace: **Wisej.Web**

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

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

Implements the [ICommand](/api/wisej.web/interfaces/wisej.web.icommand.md) 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](/api/wisej.web/interfaces/wisej.web.icommandsource.md) 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](/api/wisej.web/data-binding/wisej.web.commandargs.md#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](/api/wisej.web/buttons/wisej.web.buttonbase.md#command) property.

## Parameters

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

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) Command(execute, canExecute)

Initializes a new [Command](/api/wisej.web/data-binding/wisej.web.command.md) 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](/api/wisej.web/interfaces/wisej.web.icommandsource.md) to perform a command.                                       |
| **canExecute** | [Func\<CommandArgs\<T>, Boolean>](https://docs.microsoft.com/dotnet/api/system.func-2) | Invoked by the [ICommandSource](/api/wisej.web/interfaces/wisej.web.icommandsource.md) to determine whether it can execute the *execute* function. |

## Implements

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.web/data-binding/wisej.web.command-less-than-t-greater-than.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
