/*============================================================================= Project: SharpImage Module: itkPixelTypeConverter.cs Language: C# Author: Dan Mueller Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ Revision: $Revision: 2 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Design; using System.ComponentModel; using System.Globalization; namespace SharpImage.Main { public class itkPixelTypeConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(String)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is String) { itk.itkPixel pixel = (itk.itkPixel)context.PropertyDescriptor.GetValue(context.Instance); itk.itkPixel result; if (itk.itkPixel.TryParse(pixel.Type, value as String, out result)) return result; } return base.ConvertFrom(context, culture, value); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(String)) if (value != null) return (value as itk.itkPixel).ToString("0.0#"); else return "0"; return base.ConvertTo(context, culture, value, destinationType); } } }