Skip to content

Class ConvertedValueSource<TSource, T>

Definition

Namespace: StardewUI.Framework.Sources
Assembly: StardewUI.dll

A value source that wraps another IValueSource<T> and performs automatic conversion.

public class ConvertedValueSource<TSource, T> : 
    StardewUI.Framework.Sources.IValueSource<T>, 
    StardewUI.Framework.Sources.IValueSource

Type Parameters

TSource
The original value type, i.e. of the source.

T
The converted value type.

Inheritance
Object ⇦ ConvertedValueSource<TSource, T>

Implements
IValueSource<T>, IValueSource

Members

Constructors

Name Description
ConvertedValueSource<TSource, T>(IValueSource<TSource>, IValueConverter<TSource, T>, IValueConverter<T, TSource>) A value source that wraps another IValueSource<T> and performs automatic conversion.

Properties

Name Description
CanRead Whether or not the source can be read from, i.e. if an attempt to get the Value should succeed.
CanWrite Whether or not the source can be written back to, i.e. if an attempt to set the Value should succeed.
DisplayName Descriptive name for the property, used primarily for debug views and log/exception messages.
Value
ValueType The compile-time type of the value tracked by this source; the type parameter for IValueSource<T>.

Methods

Name Description
Update(Boolean) Checks if the value needs updating, and if so, updates Value to the latest.

Details

Constructors

ConvertedValueSource<TSource, T>(IValueSource<TSource>, IValueConverter<TSource, T>, IValueConverter<T, TSource>)

A value source that wraps another IValueSource<T> and performs automatic conversion.

public ConvertedValueSource<TSource, T>(StardewUI.Framework.Sources.IValueSource<TSource> source, StardewUI.Framework.Converters.IValueConverter<TSource, T> inputConverter, StardewUI.Framework.Converters.IValueConverter<T, TSource> outputConverter);
Parameters

source   IValueSource<TSource>
The original value source.

inputConverter   IValueConverter<TSource, T>
A converter that converts from TSource to T. If this is null, then this instance's Value will always be null and CanRead will be false regardless of the underlying source's readability.

outputConverter   IValueConverter<T, TSource>
A converter that converts from T to TSource. If this is null, then this instance cannot accept any assignments to the Value property, and CanWrite will always be false regardless of the underlying source's writability.


Properties

CanRead

Whether or not the source can be read from, i.e. if an attempt to get the Value should succeed.

public bool CanRead { get; }
Property Value

Boolean


CanWrite

Whether or not the source can be written back to, i.e. if an attempt to set the Value should succeed.

public bool CanWrite { get; }
Property Value

Boolean


DisplayName

Descriptive name for the property, used primarily for debug views and log/exception messages.

public string DisplayName { get; }
Property Value

string


Value

public T Value { get; set; }
Property Value

T


ValueType

The compile-time type of the value tracked by this source; the type parameter for IValueSource<T>.

public System.Type ValueType { get; }
Property Value

Type


Methods

Update(bool)

Checks if the value needs updating, and if so, updates Value to the latest.

public bool Update(bool force);
Parameters

force   Boolean
If true, forces the source to update its value even if it isn't considered dirty. This should never be used in a regular binding, but can be useful in sources that are intended for occasional or one-shot use such as event handler arguments.

Returns

Boolean

true if the Value was updated; false if it already held the most recent value.

Remarks

This method is called every frame, for every binding, and providing a correct return value is essential in order to avoid slowdowns due to unnecessary rebinds.