1 //-------------------------------------------------------------
2 // <copyright company=’Microsoft Corporation’>
3 // Copyright © Microsoft Corporation. All Rights Reserved.
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 // File: MapAreaCoordinatesConverter.cs
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
26 /// Converter for the array of map area coordinates
28 internal class MapAreaCoordinatesConverter
: ArrayConverter
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.
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))
45 return base.CanConvertFrom(context
, sourceType
);
49 /// Overrides the ConvertFrom method of TypeConverter.
50 /// Convert from comma separated values in the string.
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
);
73 return base.ConvertFrom(context
, culture
, value);
77 /// Overrides the ConvertTo method of TypeConverter.
78 /// Convert coordinates array to comma separated values in string.
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;
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
);