diff Source/Data/DataProvider/FirebirdMappingSchema.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Data/DataProvider/FirebirdMappingSchema.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,98 @@
+using System;
+
+namespace BLToolkit.Data.DataProvider
+{
+	using Mapping;
+
+	public class FirebirdMappingSchema : MappingSchema
+	{
+		public byte[] ConvertToByteArray(string value)
+		{
+			return System.Text.Encoding.UTF8.GetBytes(value);
+		}
+
+		public override byte[] ConvertToByteArray(object value)
+		{
+			if (value is string)
+				return ConvertToByteArray((string)value);
+
+			return base.ConvertToByteArray(value);
+		}
+
+		public bool ConvertToBoolean(string value)
+		{
+			if (value.Length == 1)
+				switch (value[0])
+				{
+					case '1': case 'T' :case 'Y' : case 't': case 'y': return true;
+					case '0': case 'F' :case 'N' : case 'f': case 'n': return false;
+				}
+
+			return Common.Convert.ToBoolean(value);
+		}
+
+		public override bool ConvertToBoolean(object value)
+		{
+			if (value is string)
+				return ConvertToBoolean((string)value);
+
+			return base.ConvertToBoolean(value);
+		}
+
+		public System.IO.Stream ConvertToStream(string value)
+		{
+			return new System.IO.MemoryStream(ConvertToByteArray(value));
+		}
+
+		public override System.IO.Stream ConvertToStream(object value)
+		{
+			if (value is string)
+				return ConvertToStream((string)value);
+
+			return base.ConvertToStream(value);
+		}
+
+#if !SILVERLIGHT
+
+		public System.Data.SqlTypes.SqlBinary ConvertToSqlBinary(string value)
+		{
+			return Common.Convert.ToSqlBinary(ConvertToByteArray(value));
+		}
+
+		public override System.Data.SqlTypes.SqlBinary ConvertToSqlBinary(object value)
+		{
+			if (value is string)
+				return ConvertToSqlBinary((string)value);
+			return base.ConvertToSqlBinary(value);
+		}
+
+		public System.Data.SqlTypes.SqlBytes ConvertToSqlBytes(string value)
+		{
+			return Common.Convert.ToSqlBytes(ConvertToByteArray(value));
+		}
+
+		public override System.Data.SqlTypes.SqlBytes ConvertToSqlBytes(object value)
+		{
+			if (value is string)
+				return ConvertToSqlBytes((string)value);
+
+			return base.ConvertToSqlBytes(value);
+		}
+
+		public override System.Data.SqlTypes.SqlGuid ConvertToSqlGuid(object value)
+		{
+			if (value is string)
+				return new System.Data.SqlTypes.SqlGuid(new Guid((string)value));
+			return base.ConvertToSqlGuid(value);
+		}
+
+#endif
+
+		public override bool? ConvertToNullableBoolean(object value)
+		{
+			if (value is string)
+				return ConvertToBoolean((string)value);
+			return base.ConvertToNullableBoolean(value);
+		}
+	}
+}