Table of Contents

Class ConverterAggregator

Namespace
Utils.Objects
Assembly
Utils.dll

Aggregates multiple IConverter instances and tries them in order.

public sealed class ConverterAggregator : IConverter
Inheritance
ConverterAggregator
Implements
Inherited Members
Extension Methods

Constructors

ConverterAggregator()

Initializes a new instance of the ConverterAggregator class with no converters.

public ConverterAggregator()

ConverterAggregator(IEnumerable<IConverter>)

Initializes a new instance of the ConverterAggregator class with a specified collection of converters.

public ConverterAggregator(IEnumerable<IConverter> converters)

Parameters

converters IEnumerable<IConverter>

A collection of converters to aggregate.

Methods

Add(IConverter)

Adds an IConverter to the aggregator if it is not already present.

public void Add(IConverter converter)

Parameters

converter IConverter

The converter to add.

CanConvert(Type, Type)

Determines whether this converter instance can convert from sourceType to targetType.

public bool CanConvert(Type sourceType, Type targetType)

Parameters

sourceType Type

The source Type.

targetType Type

The target Type.

Returns

bool

true if this instance can perform the conversion; otherwise false.

CanConvert<TFrom, TTo>()

Determines whether this converter instance can convert from TFrom to TTo.

public bool CanConvert<TFrom, TTo>()

Returns

bool

true if this instance can perform the conversion; otherwise false.

Type Parameters

TFrom

The source type.

TTo

The target type.

Convert(object, Type)

Converts the specified value to the specified targetType.

public object Convert(object value, Type targetType)

Parameters

value object

The value to convert.

targetType Type

The target Type.

Returns

object

An object of type targetType.

Exceptions

InvalidOperationException

Thrown if the conversion cannot be performed.

Convert<TFrom, TTo>(TFrom)

Converts the specified value from type TFrom to type TTo.

public TTo Convert<TFrom, TTo>(TFrom value)

Parameters

value TFrom

The value to convert.

Returns

TTo

A value of type TTo.

Type Parameters

TFrom

The source type.

TTo

The target type.

Exceptions

InvalidOperationException

Thrown if the conversion cannot be performed.

TryConvert(object, Type, Type, out object?)

Attempts to convert the specified value from sourceType to targetType.

public bool TryConvert(object value, Type sourceType, Type targetType, out object? result)

Parameters

value object

The value to convert.

sourceType Type

The source Type.

targetType Type

The target Type.

result object

When this method returns, contains the converted result if the conversion succeeded, or null if it failed.

Returns

bool

true if the conversion was successful; otherwise false.