Class ValueConverterFactory
Definition
Namespace: StardewUI.Framework.Converters
Assembly: StardewUI.dll
Standard implementation of IValueConverterFactory that allows registering new converters.
Inheritance
Object ⇦ ValueConverterFactory
Implements
IValueConverterFactory
Members
Constructors
Name | Description |
---|---|
ValueConverterFactory() | Initializes a new ValueConverterFactory instance. |
Properties
Name | Description |
---|---|
Factories | The list of factories currently registered. |
Methods
Name | Description |
---|---|
Register(IValueConverterFactory) | Registers a delegate factory that may be used to obtain a converter for which there is no explicit registration. |
TryGetConverter(Type, Type, IValueConverter) | Attempts to obtain a converter from a given source type to a given destination type. |
TryGetConverter<TSource, TDestination>(IValueConverter<TSource, TDestination>) | Attempts to obtain a converter from a given source type to a given destination type. |
TryRegister<TSource, TDestination>(IValueConverter<TSource, TDestination>) | Attempts to register a new converter. |
TryRegister<TSource, TDestination>(Func<TSource, TDestination>) | Attempts to register a new converter. |
Details
Constructors
ValueConverterFactory()
Initializes a new ValueConverterFactory instance.
Properties
Factories
The list of factories currently registered.
protected System.Collections.Generic.List<StardewUI.Framework.Converters.IValueConverterFactory> Factories { get; }
Property Value
Methods
Register(IValueConverterFactory)
Registers a delegate factory that may be used to obtain a converter for which there is no explicit registration.
Parameters
factory
IValueConverterFactory
The delegate factory.
Remarks
Use when a single converter may handle many input or output types, e.g. string-to-enum conversions.
TryGetConverter(Type, Type, IValueConverter)
Attempts to obtain a converter from a given source type to a given destination type.
public bool TryGetConverter(System.Type sourceType, System.Type destinationType, out StardewUI.Framework.Converters.IValueConverter converter);
Parameters
sourceType
Type
The type of value to be converted.
destinationType
Type
The converted value type.
converter
IValueConverter
If the method returns true
, holds the converter that converts between the specified types; otherwise null
.
Returns
true
if the conversion is supported, otherwise false
.
TryGetConverter<TSource, TDestination>(IValueConverter<TSource, TDestination>)
Attempts to obtain a converter from a given source type to a given destination type.
public bool TryGetConverter<TSource, TDestination>(out IValueConverter<TSource, TDestination> converter);
Parameters
converter
IValueConverter<TSource, TDestination>
If the method returns true
, holds the converter that converts between the specified types; otherwise null
.
Returns
true
if the conversion is supported, otherwise false
.
TryRegister<TSource, TDestination>(IValueConverter<TSource, TDestination>)
Attempts to register a new converter.
public bool TryRegister<TSource, TDestination>(StardewUI.Framework.Converters.IValueConverter<TSource, TDestination> converter);
Parameters
converter
IValueConverter<TSource, TDestination>
The converter that handles this conversion.
Returns
true
if the converter
was registered for the specified types; false
if there was already a registration or cached converter for those types.
TryRegister<TSource, TDestination>(Func<TSource, TDestination>)
Attempts to register a new converter.
Parameters
convert
Func<TSource, TDestination>
Function to convert from TSource
to TDestination
.
Returns
true
if the conversion function was registered for the specified types; false
if there was already a registration or cached converter for those types.