电子药箱通讯服务端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TypeMapProvider.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace RDH.Data
  8. {
  9. public static class TypeMapProvider
  10. {
  11. // [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  12. // [Obsolete("This method is for internal usage only", false)]
  13. public static char ReadChar(object value)
  14. {
  15. if (value == null || value is DBNull) throw new ArgumentNullException("value");
  16. string s = value as string;
  17. if (s == null || s.Length != 1) throw new ArgumentException("A single-character was expected", "value");
  18. return s[0];
  19. }
  20. public static char? ReadNullableChar(object value)
  21. {
  22. if (value == null || value is DBNull) return null;
  23. string s = value as string;
  24. if (s == null || s.Length != 1) throw new ArgumentException("A single-character was expected", "value");
  25. return s[0];
  26. }
  27. public static Guid ReadGuid(object value)
  28. {
  29. if (value == null || value is DBNull) throw new ArgumentNullException("value");
  30. string s = value as string;
  31. if (s == null) throw new ArgumentException("A single-character was expected", "value");
  32. return new Guid(s);
  33. }
  34. public static Guid? ReadNullableGuid(object value)
  35. {
  36. if (value == null || value is DBNull) return null;
  37. string s = value as string;
  38. if (s == null) throw new ArgumentException("A single-character was expected", "value");
  39. return new Guid(s);
  40. }
  41. public static bool ReadBoolean(object value)
  42. {
  43. if (value == null || value is DBNull) throw new ArgumentNullException("value");
  44. string s = value as string;
  45. return s.Trim() == "1" || s.Trim().ToLower() == "true";
  46. }
  47. public static bool? ReadNullableBoolean(object value)
  48. {
  49. if (value == null || value is DBNull) return null;
  50. string s = value as string;
  51. return s.Trim() == "1" || s.Trim().ToLower() == "true";
  52. }
  53. public static int ReadInt(object value)
  54. {
  55. if (value == null || value is DBNull) throw new ArgumentNullException("value"); ;
  56. return Convert.ToInt32(value);
  57. }
  58. public static decimal ReadDecimal(object value)
  59. {
  60. if (value == null || value is DBNull) throw new ArgumentNullException("value");
  61. return Convert.ToDecimal(value);
  62. }
  63. public static decimal? ReadNullableDecimal(object value)
  64. {
  65. if (value == null || value is DBNull) return null;
  66. return Convert.ToDecimal(value);
  67. }
  68. public static int? ReadNullableInt(object value)
  69. {
  70. if (value == null || value is DBNull) return null;
  71. return Convert.ToInt32(value);
  72. }
  73. public static Double ReadDouble(object value)
  74. {
  75. if (value == null || value is DBNull) throw new ArgumentNullException("value");
  76. return Convert.ToDouble(value);
  77. }
  78. public static Double? ReadNullableDouble(object value)
  79. {
  80. if (value == null || value is DBNull) return null;
  81. return Convert.ToDouble(value);
  82. }
  83. }
  84. }