Class Observable<T>
Encapsulor that observes a value. 👀
Namespace: GGL.Observer
Assembly: GGL.dll
Syntax
public class Observable<T>
Type Parameters
Name | Description |
---|---|
T | Class or basic type. |
Constructors
| Edit this page View SourceObservable()
Create an observable variable with no default value.
Declaration
public Observable()
Observable(T)
Create an observable variable with a default value.
Declaration
public Observable(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | Base default value |
Properties
| Edit this page View SourceHasValue
Declaration
public bool HasValue { get; }
Property Value
Type | Description |
---|---|
bool | Is there a value set? |
Remarks
Useful for basic types like integers...
Value
Declaration
public T Value { get; set; }
Property Value
Type | Description |
---|---|
T | Sets the value and eventually raise event OnChange. |
Methods
| Edit this page View SourceClear()
Clear value and raise event OnChange.
Declaration
public void Clear()
Commit()
Raise event OnChange.
Declaration
public void Commit()
Remarks
The old value in the event will be the same as the new one...
Set(T, bool)
Sets the value and eventually raise event OnChange.
Declaration
public void Set(T value, bool triggerEvent = true)
Parameters
Type | Name | Description |
---|---|---|
T | value | New value. |
bool | triggerEvent | Well... if you want to sneakily set a value, set this to false. |
Events
| Edit this page View SourceOnChange
Declaration
public event Action<T, T> OnChange
Event Type
Type | Description |
---|---|
Action<T, T> | Even raised after changes. Define a listener as follow: |
Operators
| Edit this page View Sourceimplicit operator bool(Observable<T>)
Declaration
public static implicit operator bool(Observable<T> current)
Parameters
Type | Name | Description |
---|---|---|
Observable<T> | current | Encapsulor that observes a value. 👀 |
Returns
Type | Description |
---|---|
bool | Encapsulor that observes a value. 👀 |
implicit operator T(Observable<T>)
Declaration
public static implicit operator T(Observable<T> current)
Parameters
Type | Name | Description |
---|---|---|
Observable<T> | current | Encapsulor that observes a value. 👀 |
Returns
Type | Description |
---|---|
T | Encapsulor that observes a value. 👀 |