namespace IndexFormula.Finance { using System; using System.Collections; using System.ComponentModel; using System.Globalization; public class FloatArrayConverter : ArrayConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return ((((sourceType == null) || (sourceType == typeof(string))) || (sourceType == typeof(float[]))) || base.CanConvertFrom(context, sourceType)); } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return ((((destinationType == null) || (destinationType == typeof(string))) || (destinationType == typeof(float[]))) || base.CanConvertTo(context, destinationType)); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { return null; } if (value is string) { string[] strArray = (value as string).Split(new char[] { ',' }); if (strArray.Length == 0) { return null; } float[] numArray = new float[strArray.Length]; for (int i = 0; i < numArray.Length; i++) { numArray[i] = float.Parse(strArray[i], NumberFormatInfo.InvariantInfo); } return numArray; } if (value is float[]) { return ((float[]) value).Clone(); } return base.ConvertFrom(context, culture, value); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if ((destinationType == typeof(string)) && (value is float[])) { string str = ""; foreach (float num in (float[]) value) { if (str.Length != 0) { str = str + ","; } str = str + num.ToString(); } return str; } return base.ConvertTo(context, culture, value, destinationType); } public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { return base.CreateInstance(context, propertyValues); } public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) { return true; } } }