Skip to content

Class DuckTypeClassConverterFactory

Definition

Namespace: StardewUI.Framework.Converters
Assembly: StardewUI.dll

Factory that creates duck-typing converters for class and struct types.

public class DuckTypeClassConverterFactory : 
    StardewUI.Framework.Converters.IValueConverterFactory

Inheritance
Object ⇦ DuckTypeClassConverterFactory

Implements
IValueConverterFactory

Remarks

For the conversion to be allowed:

  • The TDestination type must be annotated with DuckTypeAttribute.
  • The destination type must have either a default constructor, or a constructor that can be completely satisfied by properties/fields of the TSource type.
  • If the best or only constructor match is the default/parameterless constructor, at least one writable property on the target type must be satisfied by a property/field on the source type.

Additionally, source types may use fields or properties, but only constructor arguments and properties will be considered on the destination type.

Members

Constructors

Name Description
DuckTypeClassConverterFactory(IValueConverterFactory) Factory that creates duck-typing converters for class and struct types.

Properties

Name Description
EnableDebugOutput Whether to print MSIL output for generated conversion methods.

Methods

Name Description
TryGetConverter<TSource, TDestination>(IValueConverter<TSource, TDestination>) Attempts to obtain a converter from a given source type to a given destination type.

Details

Constructors

DuckTypeClassConverterFactory(IValueConverterFactory)

Factory that creates duck-typing converters for class and struct types.

public DuckTypeClassConverterFactory(StardewUI.Framework.Converters.IValueConverterFactory innerFactory);
Parameters

innerFactory   IValueConverterFactory
The converter factory to handle conversion of individual properties/arguments.

Remarks

For the conversion to be allowed:

  • The TDestination type must be annotated with DuckTypeAttribute.
  • The destination type must have either a default constructor, or a constructor that can be completely satisfied by properties/fields of the TSource type.
  • If the best or only constructor match is the default/parameterless constructor, at least one writable property on the target type must be satisfied by a property/field on the source type.

Additionally, source types may use fields or properties, but only constructor arguments and properties will be considered on the destination type.


Properties

EnableDebugOutput

Whether to print MSIL output for generated conversion methods.

public bool EnableDebugOutput { get; set; }
Property Value

Boolean

Remarks

Use for troubleshooting misbehaving converters or AVE crashes.


Methods

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

Boolean

true if the conversion is supported, otherwise false.