//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005, 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
namespace System.Drawing
{
- public class SizeFConverter : TypeConverter\r
- {\r
+ public class SizeFConverter : TypeConverter
+ {
public SizeFConverter ()
{
}
-\r
+
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof (string))
return base.CanConvertFrom (context, sourceType);
}
-\r
+
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof (string))
return base.CanConvertTo (context, destinationType);
}
-\r
+
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
{
string s = value as string;
return new SizeF (numSubs[0], numSubs[1]);
}
-\r
+
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
- if ((destinationType == typeof (string)) && (value is SizeF))
- return ((SizeF) value).Width.ToString(culture) + culture.TextInfo.ListSeparator
- + " " + ((SizeF) value).Height.ToString(culture);
-
- if (destinationType == typeof (InstanceDescriptor) && value is SizeF) {
- SizeF s = (SizeF) value;
- ConstructorInfo ctor = typeof(SizeF).GetConstructor (new Type[] {typeof(int), typeof(int)});
- return new InstanceDescriptor (ctor, new object[] {s.Width, s.Height});
+ if (value is SizeF) {
+ SizeF size = (SizeF) value;
+ if (destinationType == typeof (string)) {
+ return size.Width.ToString (culture) + culture.TextInfo.ListSeparator
+ + " " + size.Height.ToString (culture);
+ } else if (destinationType == typeof (InstanceDescriptor)) {
+ ConstructorInfo ctor = typeof(SizeF).GetConstructor (new Type[] {typeof(float), typeof(float)});
+ return new InstanceDescriptor (ctor, new object[] { size.Width, size.Height});
+ }
}
return base.ConvertTo (context, culture, value, destinationType);
}
-\r
+
public override object CreateInstance (ITypeDescriptorContext context, IDictionary propertyValues)
{
float w = (float) propertyValues ["Width"];
float h = (float) propertyValues ["Height"];
return new SizeF (w, h);
}
-\r
+
public override bool GetCreateInstanceSupported (ITypeDescriptorContext context)
{
return true;
}
-\r
+
public override PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value, Attribute[] attributes)
{
if (value is SizeF)
return base.GetProperties (context, value, attributes);
}
-\r
+
public override bool GetPropertiesSupported (ITypeDescriptorContext context)
{
return true;
- }\r
+ }
}
}