using System;
using System.Collections;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
namespace System.ComponentModel
{
/// Provides a type converter to convert objects to and from various other representations.
// Token: 0x02000067 RID: 103
public class CultureInfoConverter : TypeConverter
{
/// Gets a value indicating whether this converter can convert an object in the given source type to a 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 wish to convert from.
// Token: 0x060003D3 RID: 979 RVA: 0x0000B9F8 File Offset: 0x00009BF8
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}
/// Gets a value indicating whether this converter can convert an object to the given destination type using the context.
/// true if this converter can perform the conversion; otherwise, false.
/// An that provides a format context.
/// A that represents the type you wish to convert to.
// Token: 0x060003D4 RID: 980 RVA: 0x0000BA14 File Offset: 0x00009C14
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(string) || destinationType == typeof(global::System.ComponentModel.Design.Serialization.InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}
/// Converts the specified value object to a .
/// An that represents the converted value.
/// An that provides a format context.
/// A that specifies the culture to which to convert.
/// The to convert.
///
/// specifies a culture that is not valid.
/// The conversion cannot be performed.
// Token: 0x060003D5 RID: 981 RVA: 0x0000BA50 File Offset: 0x00009C50
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 (string.Compare(text, "(Default)", false) == 0)
{
return CultureInfo.InvariantCulture;
}
try
{
return new CultureInfo(text);
}
catch
{
foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
if (string.Compare(cultureInfo.DisplayName, 0, text, 0, text.Length, true) == 0)
{
return cultureInfo;
}
}
}
throw new ArgumentException(string.Format("Culture {0} cannot be converted to a CultureInfo or is not available in this environment.", value));
}
/// Converts the given value object to the specified destination type.
/// An that represents the converted .
/// An that provides a format context.
/// A that specifies the culture to which to convert.
/// The to convert.
/// The to convert the value to.
///
/// is null.
/// The conversion cannot be performed.
// Token: 0x060003D6 RID: 982 RVA: 0x0000BB14 File Offset: 0x00009D14
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
if (value == null || !(value is CultureInfo))
{
return "(Default)";
}
if (value == CultureInfo.InvariantCulture)
{
return "(Default)";
}
return ((CultureInfo)value).DisplayName;
}
else
{
if (destinationType == typeof(global::System.ComponentModel.Design.Serialization.InstanceDescriptor) && value is CultureInfo)
{
CultureInfo cultureInfo = (CultureInfo)value;
ConstructorInfo constructor = typeof(CultureInfo).GetConstructor(new Type[] { typeof(int) });
return new global::System.ComponentModel.Design.Serialization.InstanceDescriptor(constructor, new object[] { cultureInfo.LCID });
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
/// Gets a collection of standard values for a object using the specified context.
/// A containing a standard set of valid values, or null if the data type does not support a standard set of values.
/// An that provides a format context.
// Token: 0x060003D7 RID: 983 RVA: 0x0000BBD4 File Offset: 0x00009DD4
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (this._standardValues == null)
{
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
Array.Sort(cultures, new CultureInfoConverter.CultureInfoComparer());
CultureInfo[] array = new CultureInfo[cultures.Length + 1];
array[0] = CultureInfo.InvariantCulture;
Array.Copy(cultures, 0, array, 1, cultures.Length);
this._standardValues = new TypeConverter.StandardValuesCollection(array);
}
return this._standardValues;
}
/// Gets a value indicating whether the list of standard values returned from is an exhaustive list.
/// false because the returned from is not an exhaustive list of possible values (that is, other values are possible). This method never returns true.
/// An that provides a format context.
// Token: 0x060003D8 RID: 984 RVA: 0x0000BC30 File Offset: 0x00009E30
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
/// Gets a value indicating whether this object supports a standard set of values that can be picked from a list using the specified context.
/// true because should be called to find a common set of values the object supports. This method never returns false.
/// An that provides a format context.
// Token: 0x060003D9 RID: 985 RVA: 0x0000BC34 File Offset: 0x00009E34
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
// Token: 0x04000145 RID: 325
private TypeConverter.StandardValuesCollection _standardValues;
// Token: 0x02000068 RID: 104
private class CultureInfoComparer : IComparer
{
// Token: 0x060003DB RID: 987 RVA: 0x0000BC40 File Offset: 0x00009E40
public int Compare(object first, object second)
{
if (first == null)
{
if (second == null)
{
return 0;
}
return -1;
}
else
{
if (second == null)
{
return 1;
}
return string.Compare(((CultureInfo)first).DisplayName, ((CultureInfo)second).DisplayName, false, CultureInfo.CurrentCulture);
}
}
}
}
}