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> : TypeConverterType parameters
T- The type to convert.
- Inheritance
TypeConverterSimpleStringConverter<T>
Constructors
| Name | Description |
|---|---|
| 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
convertFromStringFunc<ITypeDescriptorContext?, CultureInfo?, string, T>?- A delegate used to convert strings to instances of
T, ornullif this provider does not provide this functionality. convertToStringFunc<ITypeDescriptorContext?, CultureInfo?, T, string>?- A delegate used to convert instances of
Tto strings, ornullif this provider does not provide this functionality.
Methods
| Name | Description |
|---|---|
| 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
contextITypeDescriptorContext?- An
ITypeDescriptorContextthat provides a format context. sourceTypeType- A
Typethat 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
contextITypeDescriptorContext?- An
ITypeDescriptorContextthat provides a format context. destinationTypeType?- A
Typethat 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
contextITypeDescriptorContext?- An
ITypeDescriptorContextthat provides a format context. cultureCultureInfo?- The
CultureInfoto use as the current culture. valueobject- The
Objectto 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
contextITypeDescriptorContext?- An
ITypeDescriptorContextthat provides a format context. cultureCultureInfo?- The
CultureInfoto use as the current culture. valueobject?- The
Objectto convert. destinationTypeType- A
Typethat represents the type to convert to.
Returns
object? An Object that represents the converted value.
Exceptions
NotSupportedException- The conversion cannot be performed.