[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.ComponentModel;
|
---|
| 6 | using System.Globalization;
|
---|
| 7 |
|
---|
| 8 | namespace 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 | }
|
---|