Class SimpleConverter
A simple converter implementation that uses a dictionary of delegates to convert values between types.
public class SimpleConverter : IConverter, IEnumerable<Delegate>, IEnumerable
- Inheritance
-
SimpleConverter
- Implements
- Derived
- Inherited Members
- Extension Methods
Methods
Add(Delegate)
Adds a specific conversion delegate to this converter. The delegate must have exactly one parameter and a return type of the target type.
public void Add(Delegate d)
Parameters
dDelegateA function delegate that converts one type to another.
Exceptions
- ArgumentException
Thrown if the provided delegate has more than one parameter.
CanConvert(Type, Type)
Determines whether this converter instance can convert from sourceType to targetType.
public bool CanConvert(Type sourceType, Type targetType)
Parameters
Returns
CanConvert<TFrom, TTo>()
Determines whether this converter instance can convert from TFrom to TTo.
public bool CanConvert<TFrom, TTo>()
Returns
Type Parameters
TFromThe source type.
TToThe target type.
Convert(object, Type)
Converts the specified value to the specified targetType.
public object Convert(object value, Type targetType)
Parameters
Returns
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
valueTFromThe value to convert.
Returns
- TTo
A value of type
TTo.
Type Parameters
TFromThe source type.
TToThe 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
valueobjectThe value to convert.
sourceTypeTypeThe source Type.
targetTypeTypeThe target Type.
resultobjectWhen this method returns, contains the converted result if the conversion succeeded, or null if it failed.