1: public class Triangle
2: {
3: [DataType("PointInfo")]
4: public Point A { get; set; }
5:
6: [DataType("PointInfo")]
7: public Point B { get; set; }
8:
9: [DataType("PointInfo")]
10: public Point C { get; set; }
11: }
12:
13: [TypeConverter(typeof(PointTypeConverter))]
14: public class Point
15: {
16: public double X { get; set; }
17: public double Y { get; set; }
18: public Point(double x, double y)
19: {
20: this.X = x;
21: this.Y = y;
22: }
23:
24: public static Point Parse(string point)
25: {
26: string[] split = point.Split(',');
27: if (split.Length != 2)
28: {
29: throw new FormatException("Invalid point expression.");
30: }
31: double x;
32: double y;
33: if (!double.TryParse(split[0], out x) ||!double.TryParse(split[1], out y))
34: {
35: throw new FormatException("Invalid point expression.");
36: }
37: return new Point(x, y);
38: }
39: }
40:
41: public class PointTypeConverter : TypeConverter
42: {
43: public override bool CanConvertFrom(ITypeDescriptorContext context,Type sourceType)
44: {
45: return sourceType == typeof(string);
46: }
47:
48: public override object ConvertFrom(ITypeDescriptorContext context,CultureInfo culture, object value)
49: {
50: if (value is string)
51: {
52: return Point.Parse(value as string);
53: }
54: return base.ConvertFrom(context, culture, value);
55: }
56: }