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); } } }