123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace RDH.Data
- {
- public static class TypeMapProvider
- {
- // [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
- // [Obsolete("This method is for internal usage only", false)]
- public static char ReadChar(object value)
- {
- if (value == null || value is DBNull) throw new ArgumentNullException("value");
- string s = value as string;
- if (s == null || s.Length != 1) throw new ArgumentException("A single-character was expected", "value");
- return s[0];
- }
-
-
- public static char? ReadNullableChar(object value)
- {
- if (value == null || value is DBNull) return null;
- string s = value as string;
- if (s == null || s.Length != 1) throw new ArgumentException("A single-character was expected", "value");
- return s[0];
- }
-
-
- public static Guid ReadGuid(object value)
- {
- if (value == null || value is DBNull) throw new ArgumentNullException("value");
- string s = value as string;
- if (s == null) throw new ArgumentException("A single-character was expected", "value");
- return new Guid(s);
- }
-
-
- public static Guid? ReadNullableGuid(object value)
- {
- if (value == null || value is DBNull) return null;
- string s = value as string;
- if (s == null) throw new ArgumentException("A single-character was expected", "value");
- return new Guid(s);
- }
-
- public static bool ReadBoolean(object value)
- {
- if (value == null || value is DBNull) throw new ArgumentNullException("value");
- string s = value as string;
- return s.Trim() == "1" || s.Trim().ToLower() == "true";
- }
-
- public static bool? ReadNullableBoolean(object value)
- {
- if (value == null || value is DBNull) return null;
- string s = value as string;
- return s.Trim() == "1" || s.Trim().ToLower() == "true";
- }
-
- public static int ReadInt(object value)
- {
- if (value == null || value is DBNull) throw new ArgumentNullException("value"); ;
- return Convert.ToInt32(value);
-
- }
- public static decimal ReadDecimal(object value)
- {
- if (value == null || value is DBNull) throw new ArgumentNullException("value");
- return Convert.ToDecimal(value);
- }
-
- public static decimal? ReadNullableDecimal(object value)
- {
- if (value == null || value is DBNull) return null;
- return Convert.ToDecimal(value);
-
- }
-
- public static int? ReadNullableInt(object value)
- {
- if (value == null || value is DBNull) return null;
- return Convert.ToInt32(value);
-
- }
- public static Double ReadDouble(object value)
- {
- if (value == null || value is DBNull) throw new ArgumentNullException("value");
- return Convert.ToDouble(value);
- }
- public static Double? ReadNullableDouble(object value)
- {
- if (value == null || value is DBNull) return null;
- return Convert.ToDouble(value);
-
- }
- }
- }
|