소스 검색

* SingleConverter.cs: Implement conversion from string to match MS.NET.
Set eol-style to native.
* TypeConverter.cs: Always support conversion from InstanceDescriptor. Set
eol-style to native.
* UInt16Converter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* SByteConverter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* Int16Converter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* UInt64Converter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* DecimalConverter.cs: Implement conversion from string to match MS.NET.
Set eol-style to native.
* Int64Converter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* UInt32Converter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* Int32Converter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.
* DoubleConverter.cs: Implement conversion from string to match MS.NET. Set
eol-style to native.
* BaseNumberConverter.cs: Support conversion from string containing hex
prefixes. Set eol-style to native.
* ByteConverter.cs: Implement conversion from string to match MS.NET.
Added support for converting string containing hex prefix. Set eol-style
to native.

svn path=/trunk/mcs/; revision=48543

Gert Driesen 20 년 전
부모
커밋
aaf73fa6d4

+ 28 - 4
mcs/class/System/System.ComponentModel/BaseNumberConverter.cs

@@ -36,13 +36,16 @@ namespace System.ComponentModel
 {
 	public abstract class BaseNumberConverter : TypeConverter
 	{
-
 		internal Type InnerType;
 
 		protected BaseNumberConverter()
 		{
 		}
 
+		internal abstract bool SupportHex {
+			get;
+		}
+
 		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
 		{
 			if (sourceType == typeof (string)) 
@@ -63,9 +66,20 @@ namespace System.ComponentModel
 			if (culture == null)
 				culture = CultureInfo.CurrentCulture;
 
-			if (value is string) {
+			string text = value as string;
+			if (text != null) {
 				try {
-					return Convert.ChangeType (value, InnerType, culture.NumberFormat);
+					if (SupportHex) {
+						if (text.Length >= 1 && text[0] == '#') {
+							return ConvertFromString (text.Substring (1), 16);
+						}
+
+						if (text.StartsWith ("0x") || text.StartsWith ("0X")) {
+							return ConvertFromString (text, 16);
+						}
+					}
+
+					return ConvertFromString (text, culture.NumberFormat);
 				} catch (Exception e) {
 					// LAMESPEC MS wraps the actual exception in an Exception
 					throw new Exception (value.ToString() + " is not a valid "
@@ -90,6 +104,16 @@ namespace System.ComponentModel
 
 			return base.ConvertTo (context, culture, value, destinationType);
 		}
+
+		internal abstract object ConvertFromString (string value, NumberFormatInfo format);
+
+		internal virtual object ConvertFromString (string value, int fromBase)
+		{
+			if (SupportHex) {
+				throw new NotImplementedException ();
+			} else {
+				throw new InvalidOperationException ();
+			}
+		}
 	}
 }
-

+ 16 - 0
mcs/class/System/System.ComponentModel/ByteConverter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class ByteConverter : BaseNumberConverter
@@ -36,6 +38,20 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (Byte);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return byte.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToByte (value, fromBase);
+		}
 	}
 }
 

+ 37 - 0
mcs/class/System/System.ComponentModel/ChangeLog

@@ -1,3 +1,40 @@
+2005-08-19  Gert Driesen <[email protected]>
+
+	* SingleConverter.cs: Implement conversion from string to match MS.NET.
+	Set eol-style to native.
+	* TypeConverter.cs: Always support conversion from InstanceDescriptor. 
+	Set eol-style to native.
+	* UInt16Converter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+	* SByteConverter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set
+	eol-style to native.
+	* Int16Converter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+	* UInt64Converter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+	* DecimalConverter.cs: Implement conversion from string to match MS.NET.
+	Set eol-style to native.
+	* Int64Converter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+	* UInt32Converter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+	* Int32Converter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+	* DoubleConverter.cs: Implement conversion from string to match MS.NET.
+	Set eol-style to native.
+	* BaseNumberConverter.cs: Support conversion from string containing 
+	hex prefixes. Set eol-style to native.
+	* ByteConverter.cs: Implement conversion from string to match MS.NET.
+	Added support for converting string containing hex prefix. Set 
+	eol-style to native.
+
 2005-08-18  Gert Driesen <[email protected]>
 
 	* EditorBrowsableState.cs: Changed line ending from CRLF to LF to

+ 11 - 2
mcs/class/System/System.ComponentModel/DecimalConverter.cs

@@ -36,13 +36,17 @@ using System.ComponentModel.Design.Serialization;
 
 namespace System.ComponentModel
 {
-    public class DecimalConverter : BaseNumberConverter
+	public class DecimalConverter : BaseNumberConverter
 	{
 		public DecimalConverter()
 		{
 			InnerType = typeof(Decimal);
 		}
 
+		internal override bool SupportHex {
+			get { return false; }
+		}
+
 		public override bool CanConvertTo (ITypeDescriptorContext context,
 			Type destinationType)
 		{
@@ -59,8 +63,13 @@ namespace System.ComponentModel
 				ConstructorInfo ctor = typeof(Decimal).GetConstructor (new Type[] {typeof(int[])});
 				return new InstanceDescriptor (ctor, new object[] {Decimal.GetBits (cval)});
 			}
-			Console.WriteLine (Environment.StackTrace);
+
 			return base.ConvertTo(context, culture, value, destinationType);
 		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return decimal.Parse (value, NumberStyles.Float, format);
+		}
 	}
 }

+ 11 - 0
mcs/class/System/System.ComponentModel/DoubleConverter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class DoubleConverter : BaseNumberConverter
@@ -36,5 +38,14 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (Double);
 		}
+
+		internal override bool SupportHex {
+			get { return false; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return double.Parse (value, NumberStyles.Float, format);
+		}
 	}
 }

+ 16 - 0
mcs/class/System/System.ComponentModel/Int16Converter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class Int16Converter : BaseNumberConverter
@@ -36,5 +38,19 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (Int16);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return short.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToInt16 (value, fromBase);
+		}
 	}
 }

+ 16 - 0
mcs/class/System/System.ComponentModel/Int32Converter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class Int32Converter : BaseNumberConverter
@@ -36,5 +38,19 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (Int32);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return int.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToInt32 (value, fromBase);
+		}
 	}
 }

+ 16 - 0
mcs/class/System/System.ComponentModel/Int64Converter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class Int64Converter : BaseNumberConverter
@@ -36,5 +38,19 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (Int64);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return long.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToInt64 (value, fromBase);
+		}
 	}
 }

+ 17 - 0
mcs/class/System/System.ComponentModel/SByteConverter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class SByteConverter : BaseNumberConverter
@@ -36,5 +38,20 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (SByte);
 		}
+
+		internal override bool SupportHex
+		{
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return sbyte.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToSByte (value, fromBase);
+		}
 	}
 }

+ 11 - 0
mcs/class/System/System.ComponentModel/SingleConverter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class SingleConverter : BaseNumberConverter
@@ -36,5 +38,14 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (Single);
 		}
+
+		internal override bool SupportHex {
+			get { return false; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return float.Parse (value, NumberStyles.Float, format);
+		}
 	}
 }

+ 9 - 0
mcs/class/System/System.ComponentModel/TypeConverter.cs

@@ -32,6 +32,7 @@
 
 using System;
 using System.Collections;
+using System.ComponentModel.Design.Serialization;
 using System.Globalization;
 using System.Runtime.InteropServices;
 
@@ -47,6 +48,10 @@ namespace System.ComponentModel
 
 		public virtual bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
 		{
+			if (sourceType == typeof (InstanceDescriptor)) {
+				return true;
+			}
+
 			return false;
 		}
 
@@ -67,6 +72,10 @@ namespace System.ComponentModel
 
 		public virtual object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
 		{
+			if (value is InstanceDescriptor) {
+				return ((InstanceDescriptor) value).Invoke ();
+			}
+
 			throw new NotSupportedException (this.ToString() + " cannot be created from '" +
 						         value.GetType().ToString() + "'");
 		}

+ 16 - 0
mcs/class/System/System.ComponentModel/UInt16Converter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class UInt16Converter : BaseNumberConverter
@@ -36,5 +38,19 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (UInt16);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return ushort.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToUInt16 (value, fromBase);
+		}
 	}
 }

+ 16 - 0
mcs/class/System/System.ComponentModel/UInt32Converter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class UInt32Converter : BaseNumberConverter
@@ -36,5 +38,19 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (UInt32);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return uint.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToUInt32 (value, fromBase);
+		}
 	}
 }

+ 16 - 0
mcs/class/System/System.ComponentModel/UInt64Converter.cs

@@ -28,6 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
+
 namespace System.ComponentModel
 {
 	public class UInt64Converter : BaseNumberConverter
@@ -36,5 +38,19 @@ namespace System.ComponentModel
 		{
 			InnerType = typeof (UInt64);
 		}
+
+		internal override bool SupportHex {
+			get { return true; }
+		}
+
+		internal override object ConvertFromString (string value, NumberFormatInfo format)
+		{
+			return ulong.Parse (value, NumberStyles.Integer, format);
+		}
+
+		internal override object ConvertFromString (string value, int fromBase)
+		{
+			return Convert.ToUInt64 (value, fromBase);
+		}
 	}
 }