> For the complete documentation index, see [llms.txt](https://postica.gitbook.io/binding-system-3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://postica.gitbook.io/binding-system-3/reference/api.md).

# API Cheat Sheet

The public surface, on one page.

Everything in `Postica.BindingSystem`, unless noted.

## Bind types

```csharp
Bind<T>                // the default
ReadOnlyBind<T>        // read only
WriteOnlyBind<T>       // write only
ReadOnlyBindLite<T>    // read only, no parameters, smallest serialized form
BindDataFor<T>         // no value field, must point somewhere
PhasedBind<T>          // Bind<T> with a staged pipeline
```

Common members:

```csharp
T       Value          { get; set; }   // through the pipeline
T       UnboundValue   { get; set; }   // the plain serialized value
bool    IsBound        { get; }
bool    CanRead        { get; }
bool    CanWrite       { get; }
Object  Source         { get; }
BindData<T> BindData   { get; }        // null when not bound
IAccessor<T> Accessor  { get; }

event ValueChanged<T> ValueChanged;    // (oldValue, newValue)
bool UnboundValueFiresValueChanged { get; set; }
bool UpdateOnEnable                { get; set; }

void Refresh();
void Dispose();
string ToString(string format, IFormatProvider provider);
string ToString(string varName, bool richText = true);   // extension
```

Construction:

```csharp
new Bind<float>(90f);                                  // a constant
new Bind<float>(target, "position.x");                 // source + path
new Bind<Transform>(target, "GetChild(Int32)", 1);     // with parameters
90f.Bind();                                            // extension, for field initializers
```

## Bind data

```csharp
class SimpleBindData        // source, path, mode, converters, modifiers, flags
class BindData    : SimpleBindData    // + parameters, update interval
class BindData<T> : BindData          // + typed OnValueChanged UnityEvent
```

```csharp
Object     Source        { get; set; }   // setting it resets the mode to Value
Object     SourceContext { get; set; }
string     Path          { get; set; }
BindMode   Mode          { get; }
BindFlags  Flags         { get; }
BindFlags2 Flags2        { get; }
bool       IsValid       { get; }
IConverter ReadConverter { get; }
IConverter WriteConverter{ get; }
IModifier[] Modifiers    { get; }
IModifier[] PreModifiers { get; }

bool TryEnableFlag(BindFlags flag, bool enable);
bool HasFlags(BindFlags flags);
```

## Modes and flags

```csharp
enum BindMode  { Read, Write, ReadWrite }
enum BindFlags  { ... }   // see BindFlags
enum BindFlags2 { ... }

mode.CanRead();  mode.CanWrite();
mode.ToShortName();  mode.NextMode();
mode.IsCompatibleWith(otherMode);
mode.IsCompatibleWith(canRead, canWrite);
```

## Runtime control

Extension methods on any object, plus static equivalents on `BindingEngine`.

```csharp
int  UpdateAllBinds();
int  UpdateBind(string path);
int  UpdateBind(params string[] paths);
void PauseAllBinds();
void ResumeAllBinds();
void PauseBind(string path);       // and params
void ResumeBind(string path);      // and params
void ClearAllBinds();
```

See [Controlling Bindings at Runtime](/binding-system-3/overview/runtime-control.md).

## The pipeline

```csharp
interface IConverter                     { string Id; string Description; bool IsSafe;
                                           object Convert(object value); }
interface IConverter<in T, out TResult>  { TResult Convert(T value); }   // T != TResult
interface IConverterTemplate
interface IConverterCompiler             { IConverter Compile(Type from, Type to); }

interface IModifier                      { string Id; string ShortDataDescription;
                                           BindMode ModifyMode; object Modify(BindMode, object); }
interface IReadModifier<T>               { T ModifyRead(in T value); }
interface IWriteModifier<T>              { T ModifyWrite(in T value); }
interface IReadWriteModifier<T>
interface IObjectModifier<T>
interface ISmartModifier                 { IBind BindOwner { get; set; } }
interface ISmartValueModifier<T>         { Action<ISmartModifier, T> SetValue { get; set; } }
interface INullPropagatingModifier
interface IRequiresAutoUpdate            { bool ShouldAutoUpdate; bool UpdateOnEnable; }
interface IDynamicComponent              { bool IsDynamic; }

abstract class BaseModifier<T>           // Modify / InverseModify
abstract class NumericModifier           // Modify(long) / Modify(double)
```

Registration:

```csharp
// TFrom and TTo must differ: a same-type "conversion" is a modifier, not a converter.
ConvertersFactory.Register<TFrom, TTo>(IConverter<TFrom, TTo> converter);
ConvertersFactory.Register<TFrom, TTo>(string id, Func<TFrom, TTo> fn, bool isSafe = true);
ConvertersFactory.RegisterTemplate<T>(string id = null, bool isSafe = true);

ModifiersFactory.RegisterModifier(IModifier modifier);      // throws on duplicate Id
ModifiersFactory.Register<T>(bool registerForBaseTypes = true);
ModifiersFactory.RegisterTemplate(Type modifierType, bool registerForBaseTypes = true);
```

## Accessors

`Postica.BindingSystem.Accessors`

```csharp
AccessorsFactory.GetAccessor<T>(object target, string path);
AccessorsFactory.ValueGetter<TSource, TValue>(string memberPath);
AccessorsFactory.RegisterAccessorProvider(IAccessorProvider provider);
AccessorsFactory.UnregisterAccessorProvider(IAccessorProvider provider);

interface IAccessor      { bool CanRead; bool CanWrite;
                           object GetValue(object target); void SetValue(object, object); }
interface IAccessor<T>   { T GetValue(object target); void SetValue(object, in T value); }
interface IAccessorProvider

class ObjectTypeAccessor<S, T>   // reference-type source
class ValueTypeAccessor<S, T>    // value-type source
abstract class BaseAccessorProvider<T>
```

## Variables

```csharp
BindVariablesSystem.RegisterContainer(IBindVariableContainer container);
BindVariablesSystem.UnregisterContainer(IBindVariableContainer container);
BindVariablesSystem.GetAllVariables();
BindVariablesSystem.TryGetVariable(string id, out IBindVariable variable);

interface IBindVariable          { string VariableName; Type Type; object Value;
                                   string Id; string Scope; string Description; }
interface IBindVariableContainer { bool IsAlive; IEnumerable<IBindVariable> GetAllVariables();
                                   bool TryGetVariable(string id, out IBindVariable v); }

class AssetBindVariables : ScriptableObject   // Assets ▸ Create ▸ Binding System
```

## State

```csharp
// Members made in the Inspector. The same methods on both.
class State : MonoBehaviour         // Add Component ▸ Binding System ▸ State
class StateAsset : ScriptableObject // Assets ▸ Create ▸ Binding System ▸ State Asset

int                 Count;
IEnumerable<string> Names;
bool Has(string name);
Type GetMemberType(string name);
bool TryGet<T>(string name, out T value);
T    Get<T>(string name, T fallback = default);
bool Set<T>(string name, T value);       // converts between numbers
```

## Pinning

```csharp
interface IPinnedStorage  { string Id; IEnumerable<PinnedPath> AllPaths;
                            void AddPath(PinnedPath); void RemovePath(PinnedPath); }
struct PinnedPath         { Object context; string path; SerializedType type; BitFlags flags; }

class PinnedStorageComponent : MonoBehaviour
class PinnedStorageAsset     : ScriptableObject
```

## UI Toolkit

`Postica.BindingSystem.UIToolkit`

```csharp
class BS3DataBinding : CustomBinding     // [UxmlObject]
    string BindDataJson { get; set; }    // the bind-data UXML attribute

class UIDocumentBindings : MonoBehaviour
    IReadOnlyList<UIDocumentBindEntry> Bindings { get; }
    UIDocument Document { get; }
    void Reapply();

class UIDocumentBindEntry
```

See [UI Toolkit and UXML](/binding-system-3/overview/ui-toolkit.md).

## System

```csharp
BindSystem.Version;                          // "3.0.0"
BindSystem.ProductName;
BindSystem.FullProductText;
BindSystem.IsARM64Architecture;

BindSystem.RerouteBoundFieldOf<T>(string field, string target, bool overwrite = false);
BindSystem.RerouteBoundField(Type type, string field, string target, bool overwrite = false);
BindSystem.UnrouteBoundField(Type type, string field);
```

The project-wide options, phased bindings and universal bind control, are package-internal. Change them in [Project Settings](/binding-system-3/reference/settings.md#optimization).

## The engine

`BindingEngine` is the public facade, and the extension methods above are the whole of its intended surface. The scheduler behind it, `BindingEngineInternal`, is internal: its player-loop stages, data-refresher registry and per-stage updaters are implementation detail and can change between versions.

If you need to hook something into the same stages, use an [update point](/binding-system-3/overview/modes-and-updates.md) on a binding rather than reaching for the internal type.

## Interfaces you might implement

<table><thead><tr><th width="290">Interface</th><th>What it is for</th></tr></thead><tbody><tr><td><code>IBindController</code></td><td>Marker. Lets the object control its own bindings.</td></tr><tr><td><code>IConverter&#x3C;T, TResult></code></td><td><a href="/binding-system-3/reference/extending/converters.md">Custom Converters</a></td></tr><tr><td><code>IReadModifier&#x3C;T></code> and friends</td><td><a href="/binding-system-3/reference/extending/modifiers.md">Custom Modifiers</a></td></tr><tr><td><code>IAccessorProvider</code></td><td><a href="/binding-system-3/reference/extending/accessor-providers.md">Accessor Providers</a></td></tr><tr><td><code>IValueProvider&#x3C;T></code></td><td><a href="/binding-system-3/reference/extending/value-providers.md">Value Providers</a></td></tr><tr><td><code>IBindVariableContainer</code></td><td><a href="/binding-system-3/overview/bind-variables.md">Bind Variables</a></td></tr><tr><td><code>IDataRefresher</code></td><td>An object the engine should poll.</td></tr></tbody></table>
