UnitConverter Class
Converts from a Unit object to an object of another data type and from another type to a Unit object.
public class UnitConverter : TypeConverter
- Inheritance:
- System.Object Object
Constructors
UnitConverter()
public UnitConverter()
Methods
CanConvertFrom(ITypeDescriptorContext, Type)
Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
Parameter | Type | Description |
---|---|---|
context | System.ComponentModel.ITypeDescriptorContext | An System.ComponentModel.ITypeDescriptorContext that provides a format context. |
sourceType | System.Type | A System.Type that represents the type you want to convert from. |
Returns
- System.Boolean:
true
if this converter can perform the conversion; otherwise,false
.
CanConvertTo(ITypeDescriptorContext, Type)
Returns whether this converter can convert the object to the specified type, using the specified context.
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
Parameter | Type | Description |
---|---|---|
context | System.ComponentModel.ITypeDescriptorContext | An System.ComponentModel.ITypeDescriptorContext that provides a format context. |
destinationType | System.Type | A System.Type that represents the type you want to convert to. |
Returns
- System.Boolean:
true
if this converter can perform the conversion; otherwise,false
.
ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)
Converts the given object to the type of this converter, using the specified context and culture information.
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
Parameter | Type | Description |
---|---|---|
context | System.ComponentModel.ITypeDescriptorContext | An System.ComponentModel.ITypeDescriptorContext that provides a format context. |
culture | System.Globalization.CultureInfo | The System.Globalization.CultureInfo to use as the current culture. |
value | System.Object | The System.Object to convert. |
Returns
- System.Object:
An System.Object that represents the converted value.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | The conversion cannot be performed. |
ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)
Converts the given value object to the specified type, using the specified context and culture information.
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
Parameter | Type | Description |
---|---|---|
context | System.ComponentModel.ITypeDescriptorContext | An System.ComponentModel.ITypeDescriptorContext that provides a format context. |
culture | System.Globalization.CultureInfo | A System.Globalization.CultureInfo. If null is passed, the current culture is assumed. |
value | System.Object | The System.Object to convert. |
destinationType | System.Type | The System.Type to convert the |
Returns
- System.Object:
An System.Object that represents the converted value.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.NotSupportedException | The conversion cannot be performed. |