# Modifiers

Modifiers allow you to change the values before they are set or retrieved by requesters. Modifiers provide flexibility in manipulating the bound values. Like converters, modifiers are relatively simple to implement and extend.

{% hint style="danger" %}
The modifiers must not change output value type, at most have a value which is of an inherited type relative to input value type.
{% endhint %}

<figure><img src="https://3780647524-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnpeBTRzgLGSQUWVhwqoi%2Fuploads%2FPTXO9dVPb40Ss0TM6GXb%2Fimage.png?alt=media&#x26;token=4f1cb3d0-b434-4ea6-935a-ab2707de62cf" alt="" width="563"><figcaption><p>Modifiers for Color</p></figcaption></figure>

To add a new modifier, it is sufficient to implement the `IReadWriteModifier<T>` interface:

```csharp
public class MyModifier : IReadWriteModifier<bool>
{
    public string Id => "Invert";
    public string ShortDataDescription => "[Invert X]";
    public BindMode ModifyMode => BindMode.ReadWrite;
    public object Modify(BindMode modifyMode, object value) => !((bool)value); // This is the fallback method
    public bool ModifyRead(in bool value) => !value; // Used when reading a value from source
    public bool ModifyWrite(in bool value) => !value; // Used when writing a value to source
}
```

The `IReadWriteModifier<T>` interface implements both `IReadModifier<T>` and `IWriteModifier<T>`. Implement one of them if you need only one-way modifier.

<figure><img src="https://content.gitbook.com/content/npeBTRzgLGSQUWVhwqoi/blobs/pfsZtQ5ina6vGB3t2Y6I/BS_Modifiers_Interfaces.png" alt="" width="563"><figcaption><p>Modifiers interfaces</p></figcaption></figure>

`ISmartModifier` gets the bind field it is currently attached to, while its generic version gets as well the possibility to force a value into the pipeline even when there was no request for it.

`IObjectModifier` is specifically designed to handle non-value types. It is recomended to implement this interface (or its generic version) for modifiers which intend to modify instance values and their inherited types.

The system will automatically pick up the new modifier and make it available in **Bind Menu**. To avoid auto registration of the new modifier, add `[HideMember]` attribute over the class.

{% hint style="warning" %}
The modifier must have a parameterless constructor.
{% endhint %}

For new numeric modifiers, we suggest extending `NumericModifier` for simplicity. It only requires to implement a simple `Modify(double)` method and optionally another `Modify(long)` method to cover all numeric modification cases.

Most of the modifiers have their code exposed, this is to allow users to change them at their heart's content.
