Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/DataRectConverter.cs @ 13792

Last change on this file since 13792 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.ComponentModel;
6using System.Globalization;
7
8namespace Microsoft.Research.DynamicDataDisplay.Common
9{
10  public sealed class DataRectConverter : TypeConverter
11  {
12    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
13    {
14      return (sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType);
15    }
16
17    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
18    {
19      return (destinationType == typeof(string)) || base.CanConvertTo(context, destinationType);
20    }
21
22    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
23    {
24      if (value == null)
25      {
26        throw base.GetConvertFromException(value);
27      }
28
29      string source = value as string;
30      if (source != null)
31      {
32        return DataRect.Parse(source);
33      }
34
35      return base.ConvertFrom(context, culture, value);
36    }
37
38    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
39    {
40      if (destinationType != null && value is DataRect)
41      {
42        DataRect rect = (DataRect)value;
43        if (destinationType == typeof(string))
44        {
45          return rect.ConvertToString(null, culture);
46        }
47      }
48      return base.ConvertTo(context, culture, value, destinationType);
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.