Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorVeerapuram Varadhan <v.varadhan@gmail.com>2009-04-01 01:58:38 +0400
committerVeerapuram Varadhan <v.varadhan@gmail.com>2009-04-01 01:58:38 +0400
commit02f82de85b66711025791219662dbc05709fa584 (patch)
treef54df3e04a511f3ddfd45b6d7bd68c6429650ea6 /mcs
parent4789af4bc6e5df0e7f1971c5a6640921257942eb (diff)
2009-03-31 Veerapuram Varadhan <vvaradhan@novell.com>
* Fixes rest of #480377 * DataContainer.cs (GetContainerData, GetExplicitValue): Added to handle cases where passed type overloads an explicit operator for conversion of values. svn path=/trunk/mcs/; revision=130708
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System.Data/System.Data.Common/ChangeLog5
-rw-r--r--mcs/class/System.Data/System.Data.Common/DataContainer.cs89
2 files changed, 79 insertions, 15 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/ChangeLog b/mcs/class/System.Data/System.Data.Common/ChangeLog
index 323785400a1..54d6ea9a1de 100644
--- a/mcs/class/System.Data/System.Data.Common/ChangeLog
+++ b/mcs/class/System.Data/System.Data.Common/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-31 Veerapuram Varadhan <vvaradhan@novell.com>
+
+ * DataContainer.cs (GetContainerData, GetExplicitValue): Added to handle cases
+ where passed type overloads an explicit operator for conversion of values.
+
2009-01-03 Gert Driesen <drieseng@users.sourceforge.net>
* DbCommandBuilder.cs (QuoteIdentifier): Throw NotSupportedException.
diff --git a/mcs/class/System.Data/System.Data.Common/DataContainer.cs b/mcs/class/System.Data/System.Data.Common/DataContainer.cs
index c2cf9e574e0..30ef3978734 100644
--- a/mcs/class/System.Data/System.Data.Common/DataContainer.cs
+++ b/mcs/class/System.Data/System.Data.Common/DataContainer.cs
@@ -22,6 +22,8 @@
//
using System;
using System.Collections;
+using System.Reflection;
+using System.Reflection.Emit;
namespace System.Data.Common
{
@@ -143,6 +145,63 @@ namespace System.Data.Common
return container;
}
+ internal static object GetExplicitValue (object value)
+ {
+ Type valueType = value.GetType ();
+ MethodInfo method = valueType.GetMethod ("op_Explicit", new Type[]{valueType});
+ if (method != null)
+ return (method.Invoke (value, new object[]{value}));
+ return null;
+ }
+
+ internal object GetContainerData (object value)
+ {
+ object obj;
+
+ if (_type.IsInstanceOfType (value)) {
+ return value;
+ } else if (value is IConvertible) {
+ switch (Type.GetTypeCode(_type)) {
+ case TypeCode.Int16:
+ return (Convert.ToInt16 (value));
+ case TypeCode.Int32:
+ return (Convert.ToInt32 (value));
+ case TypeCode.Int64:
+ return (Convert.ToInt64 (value));
+ case TypeCode.String:
+ return (Convert.ToString (value));
+ case TypeCode.Boolean:
+ return (Convert.ToBoolean (value));
+ case TypeCode.Byte:
+ return (Convert.ToByte (value));
+ case TypeCode.Char:
+ return (Convert.ToChar (value));
+ case TypeCode.Double:
+ return (Convert.ToDouble (value));
+ case TypeCode.SByte:
+ return (Convert.ToSByte (value));
+ case TypeCode.Single:
+ return (Convert.ToSingle (value));
+ case TypeCode.UInt16:
+ return (Convert.ToUInt16 (value));
+ case TypeCode.UInt32:
+ return (Convert.ToUInt32 (value));
+ case TypeCode.UInt64:
+ return (Convert.ToUInt64 (value));
+ case TypeCode.DateTime:
+ return (Convert.ToDateTime (value));
+ case TypeCode.Decimal:
+ return (Convert.ToDecimal (value));
+ default:
+ throw new InvalidCastException ();
+ }
+ } else if ((obj = GetExplicitValue (value)) != null) {
+ return (obj);
+ } else {
+ throw new InvalidCastException ();
+ }
+ }
+
internal bool IsNull (int index)
{
return null_values == null || null_values [index];
@@ -201,7 +260,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is bool ? (bool) value : Convert.ToBoolean (value);
+ _values [index] = (bool) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -250,7 +309,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is char ? (char) value : Convert.ToChar (value);
+ _values [index] = (char) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -303,7 +362,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is byte ? (byte) value : Convert.ToByte (value);
+ _values [index] = (byte) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -356,7 +415,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is sbyte ? (sbyte) value : Convert.ToSByte (value);
+ _values [index] = (sbyte) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -409,7 +468,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is short ? (short) value : Convert.ToInt16 (value);
+ _values [index] = (short) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -462,7 +521,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is ushort ? (ushort) value : Convert.ToUInt16 (value);
+ _values [index] = (ushort) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -515,7 +574,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is int ? (int) value : Convert.ToInt32 (value);
+ _values [index] = (int) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -568,7 +627,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is uint ? (uint) value : Convert.ToUInt32 (value);
+ _values [index] = (uint) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -621,7 +680,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is long ? (long) value : Convert.ToInt64 (value);
+ _values [index] = (long) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -674,7 +733,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is ulong ? (ulong) value : Convert.ToUInt64 (value);
+ _values [index] = (ulong) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -727,7 +786,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is float ? (float) value : Convert.ToSingle (value);
+ _values [index] = (float) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -780,7 +839,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- _values [index] = value is double ? (double) value : Convert.ToDouble (value);
+ _values [index] = (double) GetContainerData (value);
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)
@@ -894,7 +953,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- base.SetValue (index, Convert.ToDateTime (value));
+ base.SetValue (index, GetContainerData (value));
}
}
@@ -906,7 +965,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- base.SetValue (index, Convert.ToDecimal (value));
+ base.SetValue (index, GetContainerData (value));
}
}
@@ -920,7 +979,7 @@ namespace System.Data.Common
protected override void SetValue (int index, object value)
{
- SetValue (index, value is string ? (string) value : Convert.ToString (value));
+ SetValue (index, (string) GetContainerData (value));
}
protected override void SetValueFromSafeDataRecord (int index, ISafeDataRecord record, int field)