Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Web.DataVisualization / WebForm / Converters / MapAreaCoordinatesConverter.cs
blob66695efaaf8d8ccf43f7bf18f945776fe024bb97
1 //-------------------------------------------------------------
2 // <copyright company=’Microsoft Corporation’>
3 // Copyright © Microsoft Corporation. All Rights Reserved.
4 // </copyright>
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 // File: MapAreaCoordinatesConverter.cs
9 //
10 // Namespace: System.Web.UI.DataVisualization.Charting
12 // Classes: MapAreaCoordinatesConverter
14 // Purpose: Design-time converter for map area coordinates
16 // Reviewed: AG - August 7, 2002
18 //===================================================================
20 using System.ComponentModel;
21 using System.Globalization;
23 namespace System.Web.UI.DataVisualization.Charting
25 /// <summary>
26 /// Converter for the array of map area coordinates
27 /// </summary>
28 internal class MapAreaCoordinatesConverter : ArrayConverter
30 /// <summary>
31 /// Overrides the CanConvertFrom method of TypeConverter.
32 /// The ITypeDescriptorContext interface provides the context for the
33 /// conversion. Typically this interface is used at design time to
34 /// provide information about the design-time container.
35 /// </summary>
36 /// <param name="context">Descriptor context.</param>
37 /// <param name="sourceType">Convertion source type.</param>
38 /// <returns>Indicates if convertion is possible.</returns>
39 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
41 if (sourceType == typeof(string))
43 return true;
45 return base.CanConvertFrom(context, sourceType);
48 /// <summary>
49 /// Overrides the ConvertFrom method of TypeConverter.
50 /// Convert from comma separated values in the string.
51 /// </summary>
52 /// <param name="context">Descriptor context.</param>
53 /// <param name="culture">Culture information.</param>
54 /// <param name="value">Value to convert from.</param>
55 /// <returns>Indicates if convertion is possible.</returns>
56 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
58 // Can convert from string where each array element is separated by comma
59 string stringValue = value as string;
60 if (stringValue != null)
62 string[] values = stringValue.Split(new char[] { ',' });
63 float[] array = new float[values.Length];
64 for (int index = 0; index < values.Length; index++)
66 array[index] = float.Parse(values[index], System.Globalization.CultureInfo.CurrentCulture);
69 return array;
72 // Call base class
73 return base.ConvertFrom(context, culture, value);
76 /// <summary>
77 /// Overrides the ConvertTo method of TypeConverter.
78 /// Convert coordinates array to comma separated values in string.
79 /// </summary>
80 /// <param name="context">Descriptor context.</param>
81 /// <param name="culture">Culture information.</param>
82 /// <param name="value">Value to convert.</param>
83 /// <param name="destinationType">Convertion destination type.</param>
84 /// <returns>Converted object.</returns>
85 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
87 if (destinationType == typeof(string))
89 float[] array = (float[])value;
90 string result = "";
92 foreach (float d in array)
94 result += d.ToString(System.Globalization.CultureInfo.CurrentCulture) + ",";
97 return result.TrimEnd(',');
100 return base.ConvertTo(context, culture, value, destinationType);