SimpleStringConverter<T> Class

Base class for type converters that can convert instances of a specific type to and from strings.

public abstract class SimpleStringConverter<T> : TypeConverter

Type parameters

T
The type to convert.
Inheritance
TypeConverter SimpleStringConverter<T>

Constructors

NameDescription
SimpleStringConverter(Func<ITypeDescriptorContext?, CultureInfo?, string, T>?, Func<ITypeDescriptorContext?, CultureInfo?, T, string>?)Initializes a new instance of the SimpleStringConverter<T> class.

SimpleStringConverter(Func<ITypeDescriptorContext?, CultureInfo?, string, T>?, Func<ITypeDescriptorContext?, CultureInfo?, T, string>?)

Initializes a new instance of the SimpleStringConverter<T> class.

protected SimpleStringConverter(Func<ITypeDescriptorContext?, CultureInfo?, string, T>? convertFromString, Func<ITypeDescriptorContext?, CultureInfo?, T, string>? convertToString)

Parameters

convertFromString Func<ITypeDescriptorContext?, CultureInfo?, string, T>?
A delegate used to convert strings to instances of T, or null if this provider does not provide this functionality.
convertToString Func<ITypeDescriptorContext?, CultureInfo?, T, string>?
A delegate used to convert instances of T to strings, or null if this provider does not provide this functionality.

Methods

NameDescription
CanConvertFrom(ITypeDescriptorContext?, Type)Returns whether this converter can convert an object of type sourceType to T, using the specified context.
CanConvertTo(ITypeDescriptorContext?, Type?)Returns whether this converter can convert an object an instance of T to destinationType, using the specified context.
ConvertFrom(ITypeDescriptorContext?, CultureInfo?, object)Converts the given object to T, using the specified context and culture information.
ConvertTo(ITypeDescriptorContext?, CultureInfo?, object?, Type)Converts the given object to destinationType, using the specified context and culture information.

CanConvertFrom(ITypeDescriptorContext?, Type)

Returns whether this converter can convert an object of type sourceType to T, using the specified context.

public sealed override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)

Parameters

context ITypeDescriptorContext?
An ITypeDescriptorContext that provides a format context.
sourceType Type
A Type that represents the type to convert from.

Returns

bool true if this converter can perform the conversion; otherwise, false.

Remarks

This method returns true if sourceType is String and the constructor received a non-null convertFromString delegate; otherwise, it calls TypeConverter.CanConvertFrom and returns the result.

CanConvertTo(ITypeDescriptorContext?, Type?)

Returns whether this converter can convert an object an instance of T to destinationType, using the specified context.

public sealed override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)

Parameters

context ITypeDescriptorContext?
An ITypeDescriptorContext that provides a format context.
destinationType Type?
A Type that represents the type to convert to.

Returns

bool true if this converter can perform the conversion; otherwise, false.

Remarks

This method always returns true if destinationType is String; otherwise, it calls TypeConverter.CanConvertTo and returns the result.

ConvertFrom(ITypeDescriptorContext?, CultureInfo?, object)

Converts the given object to T, using the specified context and culture information.

public sealed override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)

Parameters

context ITypeDescriptorContext?
An ITypeDescriptorContext that provides a format context.
culture CultureInfo?
The CultureInfo to use as the current culture.
value object
The Object to convert.

Returns

object? An Object that represents the converted value.

Exceptions

NotSupportedException
The conversion cannot be performed.

ConvertTo(ITypeDescriptorContext?, CultureInfo?, object?, Type)

Converts the given object to destinationType, using the specified context and culture information.

public sealed override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)

Parameters

context ITypeDescriptorContext?
An ITypeDescriptorContext that provides a format context.
culture CultureInfo?
The CultureInfo to use as the current culture.
value object?
The Object to convert.
destinationType Type
A Type that represents the type to convert to.

Returns

object? An Object that represents the converted value.

Exceptions

NotSupportedException
The conversion cannot be performed.