Builder Set( T obj, string targetName, System.Action onChanged )
Builder Set( T obj, System.Func<U> read, System.Action<U> write )
Builder Set( Proxy binding )

book_4_sparkGenerated
code_blocksInput

Description

The Set method in the Sandbox.Bind.Builder class is used to establish a binding between a property of an object and a target property name. This method allows you to specify an action that will be executed whenever the target property changes. It is a part of the binding system that facilitates data synchronization between different properties or objects.

Usage

To use the Set method, you need to provide the following parameters:

  • obj: The object whose property you want to bind. This is a generic parameter, allowing you to specify any type.
  • targetName: A string representing the name of the target property you want to bind to.
  • onChanged: An Action delegate that defines the method to be called when the target property changes.

The method returns a Sandbox.Bind.Builder instance, allowing for method chaining to further configure the binding.

Example

// Example of using the Set method
var builder = new Sandbox.Bind.Builder();

// Assume we have an object with a property named "Health"
var player = new Player();

// Bind the "Health" property to a target property named "PlayerHealth"
// and specify an action to be executed when "PlayerHealth" changes
builder.Set(player, "PlayerHealth", () => {
    // Action to perform when the property changes
    Console.WriteLine("PlayerHealth has changed!");
});

// This setup allows you to react to changes in the "PlayerHealth" property of the player object.