using System;
using System.Globalization;
namespace System.ComponentModel
{
/// Provides a type converter to convert Unicode character objects to and from various other representations.
// Token: 0x02000060 RID: 96
public class CharConverter : TypeConverter
{
/// Gets a value indicating whether this converter can convert an object in the given source type to a Unicode character object using the specified context.
/// true if this converter can perform the conversion; otherwise, false.
/// An that provides a format context.
/// A that represents the type you want to convert from.
// Token: 0x060003B3 RID: 947 RVA: 0x0000B5E8 File Offset: 0x000097E8
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}
/// Converts the given object to a Unicode character object.
/// An that represents the converted .
/// An that provides a format context.
/// The culture into which will be converted.
/// The to convert.
///
/// is not a valid value for the target type.
/// The conversion cannot be performed.
// Token: 0x060003B4 RID: 948 RVA: 0x0000B604 File Offset: 0x00009804
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string text = value as string;
if (text == null)
{
return base.ConvertFrom(context, culture, value);
}
if (text.Length > 1)
{
text = text.Trim();
}
if (text.Length > 1)
{
throw new FormatException(string.Format("String {0} is not a valid Char: it has to be less than or equal to one char long.", text));
}
if (text.Length == 0)
{
return '\0';
}
return text[0];
}
/// Converts the given value object to a Unicode character object using the arguments.
/// An that represents the converted value.
/// An that provides a format context.
/// The culture into which will be converted.
/// The to convert.
/// The to convert the value to.
/// The conversion cannot be performed.
// Token: 0x060003B5 RID: 949 RVA: 0x0000B678 File Offset: 0x00009878
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType != typeof(string) || value == null || !(value is char))
{
return base.ConvertTo(context, culture, value, destinationType);
}
char c = (char)value;
if (c == '\0')
{
return string.Empty;
}
return new string(c, 1);
}
}
}