public ConvertTo ( ITypeDescriptorContext context, |
||
context | ITypeDescriptorContext | Additional context for conversion. |
culture | The culture to use for conversion. | |
value | object | The |
destinationType | The type of the destination object. | |
return | object |
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var enc = value as Encoding;
if (null != enc && this.CanConvertTo(context, destinationType))
{
if (typeof(string) == destinationType)
{
return enc.WebName;
}
else if (IsNumeric(destinationType))
{
return Convert.ChangeType(enc.CodePage, destinationType, CultureInfo.InvariantCulture);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
public void ConvertToInteger() { var converter = new EncodingConverter(); Assert.IsTrue(converter.CanConvertTo(typeof(int)), "Cannot convert to an integer."); var value = (int)converter.ConvertTo(Encoding.UTF8, typeof(int)); Assert.AreEqual <int>(65001, value, "Could not convert to an integer."); }