ConverterService.ResolveConverter(Type, Type) method¶
Defined in
Type: ConverterService
Namespace: ReactiveUI
Assembly: ReactiveUI.Core.dll
Applies to
net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471
public object? ResolveConverter(Type fromType, Type toType)
Summary: Resolves the best converter for the specified type pair.
Parameters
| Name | Type | Description |
|---|---|---|
fromType | Type | The source type to convert from. |
toType | Type | The target type to convert to. |
Returns: object? --
The best converter for the type pair (either typed or fallback), or null if no converter is available.
Remarks
This method implements the two-phase converter selection algorithm:
- 1.
Phase 1: Try to find an exact type-pair match in TypedConverters. If found, return the typed converter with the highest affinity.
- 2.
Phase 2: If no typed converter found, search FallbackConverters. Return the fallback converter with the highest affinity for the runtime types.
This method is thread-safe and lock-free, making it safe to call from multiple threads concurrently.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown if fromType or toType is null. |
Examples
var converter = converterService.ResolveConverter(typeof(int), typeof(string));
if (converter is IBindingTypeConverter typedConverter)
{
// Use typed converter
}
else if (converter is IBindingFallbackConverter fallbackConverter)
{
// Use fallback converter
}