Independent<T>

Update Controls tracks dependencies within your application. The things that it depends upon are Independents. Independent<T> is used as a field whenever you want Update Controls to track changes.

Declare the Independent<T> as a private field. You can replace T with a simple type like “int” or “string”. Or you can replace it with an object type, like “Person”.

public class Person
{
    private Independent<string> _firstName = new Independent<string>();
    private Independent<string> _lastName = new Independent<string>();
    private Independent<Person> _spouse = new Independent<Person>();
}

Always initialize the field to a new Independent<T>. Forgetting this step will lead to null reference exceptions.

Expose the properties as the raw type T. The getter can return the Independent<T>, and it will be automatically converted to the raw type. But the setter has to assign to the Value property of the field.

public class Person
{
    private Independent<string> _firstName = new Independent<string>();
    private Independent<string> _lastName = new Independent<string>();
    private Independent<Person> _spouse = new Independent<Person>();

    public string FirstName
    {
        get { return _firstName; }
        set { _firstName.Value = value; }
    }

    public string LastName
    {
        get { return _lastName; }
        set { _lastName.Value = value; }
    }

    public Person Spouse
    {
        get { return _spouse; }
        set { _spouse.Value = value; }
    }
}

If you need to initialize the value of the field, pass the initial value to the Independent<T> constructor.