Mercurial > pub > bltoolkit
comparison Source/Common/Convert.generated.cs @ 0:f990fcb411a9
Копия текущей версии из github
| author | cin |
|---|---|
| date | Thu, 27 Mar 2014 21:46:09 +0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f990fcb411a9 |
|---|---|
| 1 //--------------------------------------------------------------------------------------------------- | |
| 2 // <auto-generated> | |
| 3 // This code was generated by BLToolkit template for T4. | |
| 4 // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. | |
| 5 // </auto-generated> | |
| 6 //--------------------------------------------------------------------------------------------------- | |
| 7 using System; | |
| 8 using System.Data.Linq; | |
| 9 using System.Data.SqlTypes; | |
| 10 using System.Globalization; | |
| 11 using System.IO; | |
| 12 using System.Xml; | |
| 13 #if !SILVERLIGHT | |
| 14 using System.Xml.Linq; | |
| 15 #endif | |
| 16 | |
| 17 namespace BLToolkit.Common | |
| 18 { | |
| 19 using Properties; | |
| 20 | |
| 21 public partial class Convert | |
| 22 { | |
| 23 #region Simple Types | |
| 24 | |
| 25 #region Boolean | |
| 26 | |
| 27 // Simple Types | |
| 28 // | |
| 29 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 30 public static Boolean ToBoolean(Byte p) { return p != 0; } | |
| 31 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 32 public static Boolean ToBoolean(Decimal p) { return p != 0; } | |
| 33 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 34 public static Boolean ToBoolean(Double p) { return p != 0; } | |
| 35 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 36 public static Boolean ToBoolean(Int16 p) { return p != 0; } | |
| 37 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 38 public static Boolean ToBoolean(Int32 p) { return p != 0; } | |
| 39 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 40 public static Boolean ToBoolean(Int64 p) { return p != 0; } | |
| 41 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 42 [CLSCompliant(false)] | |
| 43 public static Boolean ToBoolean(SByte p) { return p != 0; } | |
| 44 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 45 public static Boolean ToBoolean(Single p) { return p != 0; } | |
| 46 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 47 public static Boolean ToBoolean(String p) { return p == null? Configuration.NullableValues.Boolean : p.Length == 1 ? ToBoolean(p[0]) : Boolean.Parse(p); } | |
| 48 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 49 [CLSCompliant(false)] | |
| 50 public static Boolean ToBoolean(UInt16 p) { return p != 0; } | |
| 51 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 52 [CLSCompliant(false)] | |
| 53 public static Boolean ToBoolean(UInt32 p) { return p != 0; } | |
| 54 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 55 [CLSCompliant(false)] | |
| 56 public static Boolean ToBoolean(UInt64 p) { return p != 0; } | |
| 57 | |
| 58 // Nullable Types | |
| 59 // | |
| 60 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 61 public static Boolean ToBoolean(Boolean? p) { return p.HasValue && p.Value; } | |
| 62 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 63 public static Boolean ToBoolean(Byte? p) { return p.HasValue && p.Value != 0; } | |
| 64 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 65 public static Boolean ToBoolean(Char? p) { return p.HasValue && ToBoolean(p.Value); } | |
| 66 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 67 public static Boolean ToBoolean(Decimal? p) { return p.HasValue && p.Value != 0; } | |
| 68 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 69 public static Boolean ToBoolean(Double? p) { return p.HasValue && p.Value != 0; } | |
| 70 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 71 public static Boolean ToBoolean(Int16? p) { return p.HasValue && p.Value != 0; } | |
| 72 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 73 public static Boolean ToBoolean(Int32? p) { return p.HasValue && p.Value != 0; } | |
| 74 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 75 public static Boolean ToBoolean(Int64? p) { return p.HasValue && p.Value != 0; } | |
| 76 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 77 [CLSCompliant(false)] | |
| 78 public static Boolean ToBoolean(SByte? p) { return p.HasValue && p.Value != 0; } | |
| 79 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 80 public static Boolean ToBoolean(Single? p) { return p.HasValue && p.Value != 0; } | |
| 81 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 82 [CLSCompliant(false)] | |
| 83 public static Boolean ToBoolean(UInt16? p) { return p.HasValue && p.Value != 0; } | |
| 84 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 85 [CLSCompliant(false)] | |
| 86 public static Boolean ToBoolean(UInt32? p) { return p.HasValue && p.Value != 0; } | |
| 87 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 88 [CLSCompliant(false)] | |
| 89 public static Boolean ToBoolean(UInt64? p) { return p.HasValue && p.Value != 0; } | |
| 90 | |
| 91 // Other Types | |
| 92 // | |
| 93 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 94 public static Boolean ToBoolean(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Boolean : BitConverter.ToBoolean(p.ToArray(), 0); } | |
| 95 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 96 public static Boolean ToBoolean(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Boolean : BitConverter.ToBoolean(p, 0); } | |
| 97 | |
| 98 #if !SILVERLIGHT | |
| 99 | |
| 100 // Sql Types | |
| 101 // | |
| 102 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 103 public static Boolean ToBoolean(SqlBoolean p) { return !p.IsNull && p.Value; } | |
| 104 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 105 public static Boolean ToBoolean(SqlByte p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 106 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 107 public static Boolean ToBoolean(SqlDecimal p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 108 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 109 public static Boolean ToBoolean(SqlDouble p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 110 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 111 public static Boolean ToBoolean(SqlInt16 p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 112 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 113 public static Boolean ToBoolean(SqlInt32 p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 114 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 115 public static Boolean ToBoolean(SqlInt64 p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 116 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 117 public static Boolean ToBoolean(SqlMoney p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 118 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 119 public static Boolean ToBoolean(SqlSingle p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 120 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 121 public static Boolean ToBoolean(SqlString p) { return !p.IsNull && ToBoolean(p.Value); } | |
| 122 | |
| 123 #endif | |
| 124 | |
| 125 // From Object | |
| 126 // | |
| 127 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Boolean</c> value.</summary> | |
| 128 public static Boolean ToBoolean(object p) | |
| 129 { | |
| 130 if (p == null) return Configuration.NullableValues.Boolean; | |
| 131 | |
| 132 var type = p.GetType(); | |
| 133 | |
| 134 // Primitive types | |
| 135 // | |
| 136 switch (Type.GetTypeCode(type)) | |
| 137 { | |
| 138 case TypeCode.DBNull : return Configuration.NullableValues.Boolean; | |
| 139 case TypeCode.Boolean : return (Boolean)p; | |
| 140 case TypeCode.Char : return ToBoolean((Char) p); | |
| 141 case TypeCode.String : return ToBoolean((String) p); | |
| 142 case TypeCode.SByte : return ToBoolean((SByte) p); | |
| 143 case TypeCode.Int16 : return ToBoolean((Int16) p); | |
| 144 case TypeCode.Int32 : return ToBoolean((Int32) p); | |
| 145 case TypeCode.Int64 : return ToBoolean((Int64) p); | |
| 146 case TypeCode.Byte : return ToBoolean((Byte) p); | |
| 147 case TypeCode.UInt16 : return ToBoolean((UInt16) p); | |
| 148 case TypeCode.UInt32 : return ToBoolean((UInt32) p); | |
| 149 case TypeCode.UInt64 : return ToBoolean((UInt64) p); | |
| 150 case TypeCode.Single : return ToBoolean((Single) p); | |
| 151 case TypeCode.Double : return ToBoolean((Double) p); | |
| 152 case TypeCode.Decimal : return ToBoolean((Decimal)p); | |
| 153 } | |
| 154 | |
| 155 // Nullable Types | |
| 156 // | |
| 157 if (type.IsGenericType) | |
| 158 { | |
| 159 if (p is Boolean?) return ToBoolean((Boolean?) p); | |
| 160 if (p is Byte?) return ToBoolean((Byte?) p); | |
| 161 if (p is Char?) return ToBoolean((Char?) p); | |
| 162 if (p is Decimal?) return ToBoolean((Decimal?) p); | |
| 163 if (p is Double?) return ToBoolean((Double?) p); | |
| 164 if (p is Int16?) return ToBoolean((Int16?) p); | |
| 165 if (p is Int32?) return ToBoolean((Int32?) p); | |
| 166 if (p is Int64?) return ToBoolean((Int64?) p); | |
| 167 if (p is SByte?) return ToBoolean((SByte?) p); | |
| 168 if (p is Single?) return ToBoolean((Single?) p); | |
| 169 if (p is UInt16?) return ToBoolean((UInt16?) p); | |
| 170 if (p is UInt32?) return ToBoolean((UInt32?) p); | |
| 171 if (p is UInt64?) return ToBoolean((UInt64?) p); | |
| 172 } | |
| 173 | |
| 174 // Other Types | |
| 175 // | |
| 176 if (p is Binary) return ToBoolean((Binary) p); | |
| 177 if (p is Byte[]) return ToBoolean((Byte[]) p); | |
| 178 | |
| 179 #if !SILVERLIGHT | |
| 180 | |
| 181 // Sql Types | |
| 182 // | |
| 183 if (p is INullable) | |
| 184 { | |
| 185 if (p is SqlBoolean) return ToBoolean((SqlBoolean)p); | |
| 186 if (p is SqlByte) return ToBoolean((SqlByte) p); | |
| 187 if (p is SqlDecimal) return ToBoolean((SqlDecimal)p); | |
| 188 if (p is SqlDouble) return ToBoolean((SqlDouble) p); | |
| 189 if (p is SqlInt16) return ToBoolean((SqlInt16) p); | |
| 190 if (p is SqlInt32) return ToBoolean((SqlInt32) p); | |
| 191 if (p is SqlInt64) return ToBoolean((SqlInt64) p); | |
| 192 if (p is SqlMoney) return ToBoolean((SqlMoney) p); | |
| 193 if (p is SqlSingle) return ToBoolean((SqlSingle) p); | |
| 194 if (p is SqlString) return ToBoolean((SqlString) p); | |
| 195 } | |
| 196 | |
| 197 #endif | |
| 198 | |
| 199 if (p is IConvertible) return ((IConvertible)p).ToBoolean(null); | |
| 200 | |
| 201 throw CreateInvalidCastException(p.GetType(), typeof(Boolean)); | |
| 202 } | |
| 203 | |
| 204 #endregion | |
| 205 | |
| 206 #region Byte | |
| 207 | |
| 208 // Simple Types | |
| 209 // | |
| 210 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Byte</c> value.</summary> | |
| 211 public static Byte ToByte(Boolean p) { return p ? (Byte)1 : (Byte)0; } | |
| 212 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Byte</c> value.</summary> | |
| 213 public static Byte ToByte(Char p) { return checked((Byte)p); } | |
| 214 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Byte</c> value.</summary> | |
| 215 public static Byte ToByte(Decimal p) { return checked((Byte)p); } | |
| 216 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Byte</c> value.</summary> | |
| 217 public static Byte ToByte(Double p) { return checked((Byte)p); } | |
| 218 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Byte</c> value.</summary> | |
| 219 public static Byte ToByte(Int16 p) { return checked((Byte)p); } | |
| 220 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Byte</c> value.</summary> | |
| 221 public static Byte ToByte(Int32 p) { return checked((Byte)p); } | |
| 222 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Byte</c> value.</summary> | |
| 223 public static Byte ToByte(Int64 p) { return checked((Byte)p); } | |
| 224 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Byte</c> value.</summary> | |
| 225 [CLSCompliant(false)] | |
| 226 public static Byte ToByte(SByte p) { return checked((Byte)p); } | |
| 227 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Byte</c> value.</summary> | |
| 228 public static Byte ToByte(Single p) { return checked((Byte)p); } | |
| 229 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Byte</c> value.</summary> | |
| 230 public static Byte ToByte(String p) { return p == null? Configuration.NullableValues.Byte : Byte.Parse(p); } | |
| 231 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Byte</c> value.</summary> | |
| 232 [CLSCompliant(false)] | |
| 233 public static Byte ToByte(UInt16 p) { return checked((Byte)p); } | |
| 234 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Byte</c> value.</summary> | |
| 235 [CLSCompliant(false)] | |
| 236 public static Byte ToByte(UInt32 p) { return checked((Byte)p); } | |
| 237 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Byte</c> value.</summary> | |
| 238 [CLSCompliant(false)] | |
| 239 public static Byte ToByte(UInt64 p) { return checked((Byte)p); } | |
| 240 | |
| 241 // Nullable Types | |
| 242 // | |
| 243 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 244 public static Byte ToByte(Boolean? p) { return p.HasValue && p.Value ? (Byte)1: (Byte)0; } | |
| 245 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 246 public static Byte ToByte(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Byte; } | |
| 247 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 248 public static Byte ToByte(Char? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 249 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 250 public static Byte ToByte(Decimal? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 251 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 252 public static Byte ToByte(Double? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 253 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 254 public static Byte ToByte(Int16? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 255 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 256 public static Byte ToByte(Int32? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 257 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 258 public static Byte ToByte(Int64? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 259 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 260 [CLSCompliant(false)] | |
| 261 public static Byte ToByte(SByte? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 262 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 263 public static Byte ToByte(Single? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 264 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 265 [CLSCompliant(false)] | |
| 266 public static Byte ToByte(UInt16? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 267 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 268 [CLSCompliant(false)] | |
| 269 public static Byte ToByte(UInt32? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 270 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Byte</c> value.</summary> | |
| 271 [CLSCompliant(false)] | |
| 272 public static Byte ToByte(UInt64? p) { return p.HasValue ? checked((Byte)p.Value) : Configuration.NullableValues.Byte; } | |
| 273 | |
| 274 // Other Types | |
| 275 // | |
| 276 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Byte</c> value.</summary> | |
| 277 public static Byte ToByte(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Byte : p.ToArray()[0]; } | |
| 278 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Byte</c> value.</summary> | |
| 279 public static Byte ToByte(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Byte : p[0]; } | |
| 280 | |
| 281 #if !SILVERLIGHT | |
| 282 | |
| 283 // Sql Types | |
| 284 // | |
| 285 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Byte</c> value.</summary> | |
| 286 public static Byte ToByte(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 287 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Byte</c> value.</summary> | |
| 288 public static Byte ToByte(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Byte : p.Value; } | |
| 289 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Byte</c> value.</summary> | |
| 290 public static Byte ToByte(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 291 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Byte</c> value.</summary> | |
| 292 public static Byte ToByte(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 293 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Byte</c> value.</summary> | |
| 294 public static Byte ToByte(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 295 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Byte</c> value.</summary> | |
| 296 public static Byte ToByte(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 297 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Byte</c> value.</summary> | |
| 298 public static Byte ToByte(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 299 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Byte</c> value.</summary> | |
| 300 public static Byte ToByte(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 301 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Byte</c> value.</summary> | |
| 302 public static Byte ToByte(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 303 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Byte</c> value.</summary> | |
| 304 public static Byte ToByte(SqlString p) { return p.IsNull ? Configuration.NullableValues.Byte : ToByte(p.Value); } | |
| 305 | |
| 306 #endif | |
| 307 | |
| 308 // From Object | |
| 309 // | |
| 310 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Byte</c> value.</summary> | |
| 311 public static Byte ToByte(object p) | |
| 312 { | |
| 313 if (p == null) return Configuration.NullableValues.Byte; | |
| 314 | |
| 315 var type = p.GetType(); | |
| 316 | |
| 317 // Primitive types | |
| 318 // | |
| 319 switch (Type.GetTypeCode(type)) | |
| 320 { | |
| 321 case TypeCode.DBNull : return Configuration.NullableValues.Byte; | |
| 322 case TypeCode.Byte : return (Byte)p; | |
| 323 case TypeCode.SByte : return ToByte((SByte) p); | |
| 324 case TypeCode.Int16 : return ToByte((Int16) p); | |
| 325 case TypeCode.Int32 : return ToByte((Int32) p); | |
| 326 case TypeCode.Int64 : return ToByte((Int64) p); | |
| 327 case TypeCode.UInt16 : return ToByte((UInt16) p); | |
| 328 case TypeCode.UInt32 : return ToByte((UInt32) p); | |
| 329 case TypeCode.UInt64 : return ToByte((UInt64) p); | |
| 330 case TypeCode.Single : return ToByte((Single) p); | |
| 331 case TypeCode.Double : return ToByte((Double) p); | |
| 332 case TypeCode.Decimal : return ToByte((Decimal)p); | |
| 333 case TypeCode.Char : return ToByte((Char) p); | |
| 334 case TypeCode.String : return ToByte((String) p); | |
| 335 case TypeCode.Boolean : return ToByte((Boolean)p); | |
| 336 } | |
| 337 | |
| 338 // Nullable Types | |
| 339 // | |
| 340 if (type.IsGenericType) | |
| 341 { | |
| 342 if (p is Boolean?) return ToByte((Boolean?) p); | |
| 343 if (p is Byte?) return ToByte((Byte?) p); | |
| 344 if (p is Char?) return ToByte((Char?) p); | |
| 345 if (p is Decimal?) return ToByte((Decimal?) p); | |
| 346 if (p is Double?) return ToByte((Double?) p); | |
| 347 if (p is Int16?) return ToByte((Int16?) p); | |
| 348 if (p is Int32?) return ToByte((Int32?) p); | |
| 349 if (p is Int64?) return ToByte((Int64?) p); | |
| 350 if (p is SByte?) return ToByte((SByte?) p); | |
| 351 if (p is Single?) return ToByte((Single?) p); | |
| 352 if (p is UInt16?) return ToByte((UInt16?) p); | |
| 353 if (p is UInt32?) return ToByte((UInt32?) p); | |
| 354 if (p is UInt64?) return ToByte((UInt64?) p); | |
| 355 } | |
| 356 | |
| 357 // Other Types | |
| 358 // | |
| 359 if (p is Binary) return ToByte((Binary) p); | |
| 360 if (p is Byte[]) return ToByte((Byte[]) p); | |
| 361 | |
| 362 #if !SILVERLIGHT | |
| 363 | |
| 364 // Sql Types | |
| 365 // | |
| 366 if (p is INullable) | |
| 367 { | |
| 368 if (p is SqlBoolean) return ToByte((SqlBoolean)p); | |
| 369 if (p is SqlByte) return ToByte((SqlByte) p); | |
| 370 if (p is SqlDecimal) return ToByte((SqlDecimal)p); | |
| 371 if (p is SqlDouble) return ToByte((SqlDouble) p); | |
| 372 if (p is SqlInt16) return ToByte((SqlInt16) p); | |
| 373 if (p is SqlInt32) return ToByte((SqlInt32) p); | |
| 374 if (p is SqlInt64) return ToByte((SqlInt64) p); | |
| 375 if (p is SqlMoney) return ToByte((SqlMoney) p); | |
| 376 if (p is SqlSingle) return ToByte((SqlSingle) p); | |
| 377 if (p is SqlString) return ToByte((SqlString) p); | |
| 378 } | |
| 379 | |
| 380 #endif | |
| 381 | |
| 382 if (p is IConvertible) return ((IConvertible)p).ToByte(null); | |
| 383 | |
| 384 throw CreateInvalidCastException(p.GetType(), typeof(Byte)); | |
| 385 } | |
| 386 | |
| 387 #endregion | |
| 388 | |
| 389 #region Char | |
| 390 | |
| 391 // Simple Types | |
| 392 // | |
| 393 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Char</c> value.</summary> | |
| 394 public static Char ToChar(Boolean p) { return p ? (Char)1 : (Char)0; } | |
| 395 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Char</c> value.</summary> | |
| 396 public static Char ToChar(Byte p) { return checked((Char)p); } | |
| 397 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Char</c> value.</summary> | |
| 398 public static Char ToChar(Decimal p) { return checked((Char)p); } | |
| 399 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Char</c> value.</summary> | |
| 400 public static Char ToChar(Double p) { return checked((Char)p); } | |
| 401 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Char</c> value.</summary> | |
| 402 public static Char ToChar(Int16 p) { return checked((Char)p); } | |
| 403 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Char</c> value.</summary> | |
| 404 public static Char ToChar(Int32 p) { return checked((Char)p); } | |
| 405 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Char</c> value.</summary> | |
| 406 public static Char ToChar(Int64 p) { return checked((Char)p); } | |
| 407 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Char</c> value.</summary> | |
| 408 [CLSCompliant(false)] | |
| 409 public static Char ToChar(SByte p) { return checked((Char)p); } | |
| 410 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Char</c> value.</summary> | |
| 411 public static Char ToChar(Single p) { return checked((Char)p); } | |
| 412 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Char</c> value.</summary> | |
| 413 public static Char ToChar(String p) { return string.IsNullOrEmpty(p)? (Char)0 : p[0]; } | |
| 414 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Char</c> value.</summary> | |
| 415 [CLSCompliant(false)] | |
| 416 public static Char ToChar(UInt16 p) { return checked((Char)p); } | |
| 417 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Char</c> value.</summary> | |
| 418 [CLSCompliant(false)] | |
| 419 public static Char ToChar(UInt32 p) { return checked((Char)p); } | |
| 420 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Char</c> value.</summary> | |
| 421 [CLSCompliant(false)] | |
| 422 public static Char ToChar(UInt64 p) { return checked((Char)p); } | |
| 423 | |
| 424 // Nullable Types | |
| 425 // | |
| 426 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Char</c> value.</summary> | |
| 427 public static Char ToChar(Boolean? p) { return p.HasValue && p.Value ? (Char)1: (Char)0; } | |
| 428 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Char</c> value.</summary> | |
| 429 public static Char ToChar(Byte? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 430 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Char</c> value.</summary> | |
| 431 public static Char ToChar(Char? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Char; } | |
| 432 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Char</c> value.</summary> | |
| 433 public static Char ToChar(Decimal? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 434 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Char</c> value.</summary> | |
| 435 public static Char ToChar(Double? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 436 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Char</c> value.</summary> | |
| 437 public static Char ToChar(Int16? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 438 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Char</c> value.</summary> | |
| 439 public static Char ToChar(Int32? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 440 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Char</c> value.</summary> | |
| 441 public static Char ToChar(Int64? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 442 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Char</c> value.</summary> | |
| 443 [CLSCompliant(false)] | |
| 444 public static Char ToChar(SByte? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 445 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Char</c> value.</summary> | |
| 446 public static Char ToChar(Single? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 447 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Char</c> value.</summary> | |
| 448 [CLSCompliant(false)] | |
| 449 public static Char ToChar(UInt16? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 450 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Char</c> value.</summary> | |
| 451 [CLSCompliant(false)] | |
| 452 public static Char ToChar(UInt32? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 453 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Char</c> value.</summary> | |
| 454 [CLSCompliant(false)] | |
| 455 public static Char ToChar(UInt64? p) { return p.HasValue ? checked((Char)p.Value) : Configuration.NullableValues.Char; } | |
| 456 | |
| 457 // Other Types | |
| 458 // | |
| 459 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Char</c> value.</summary> | |
| 460 public static Char ToChar(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Char : BitConverter.ToChar(p.ToArray(), 0); } | |
| 461 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Char</c> value.</summary> | |
| 462 public static Char ToChar(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Char : BitConverter.ToChar(p, 0); } | |
| 463 | |
| 464 #if !SILVERLIGHT | |
| 465 | |
| 466 // Sql Types | |
| 467 // | |
| 468 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Char</c> value.</summary> | |
| 469 public static Char ToChar(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 470 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Char</c> value.</summary> | |
| 471 public static Char ToChar(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 472 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Char</c> value.</summary> | |
| 473 public static Char ToChar(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 474 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Char</c> value.</summary> | |
| 475 public static Char ToChar(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 476 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Char</c> value.</summary> | |
| 477 public static Char ToChar(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 478 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Char</c> value.</summary> | |
| 479 public static Char ToChar(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 480 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Char</c> value.</summary> | |
| 481 public static Char ToChar(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 482 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Char</c> value.</summary> | |
| 483 public static Char ToChar(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 484 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Char</c> value.</summary> | |
| 485 public static Char ToChar(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 486 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Char</c> value.</summary> | |
| 487 public static Char ToChar(SqlString p) { return p.IsNull ? Configuration.NullableValues.Char : ToChar(p.Value); } | |
| 488 | |
| 489 #endif | |
| 490 | |
| 491 // From Object | |
| 492 // | |
| 493 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Char</c> value.</summary> | |
| 494 public static Char ToChar(object p) | |
| 495 { | |
| 496 if (p == null) return Configuration.NullableValues.Char; | |
| 497 | |
| 498 var type = p.GetType(); | |
| 499 | |
| 500 // Primitive types | |
| 501 // | |
| 502 switch (Type.GetTypeCode(type)) | |
| 503 { | |
| 504 case TypeCode.DBNull : return Configuration.NullableValues.Char; | |
| 505 case TypeCode.Char : return (Char)p; | |
| 506 case TypeCode.SByte : return ToChar((SByte) p); | |
| 507 case TypeCode.Int16 : return ToChar((Int16) p); | |
| 508 case TypeCode.Int32 : return ToChar((Int32) p); | |
| 509 case TypeCode.Int64 : return ToChar((Int64) p); | |
| 510 case TypeCode.Byte : return ToChar((Byte) p); | |
| 511 case TypeCode.UInt16 : return ToChar((UInt16) p); | |
| 512 case TypeCode.UInt32 : return ToChar((UInt32) p); | |
| 513 case TypeCode.UInt64 : return ToChar((UInt64) p); | |
| 514 case TypeCode.Single : return ToChar((Single) p); | |
| 515 case TypeCode.Double : return ToChar((Double) p); | |
| 516 case TypeCode.Decimal : return ToChar((Decimal)p); | |
| 517 case TypeCode.String : return ToChar((String) p); | |
| 518 case TypeCode.Boolean : return ToChar((Boolean)p); | |
| 519 } | |
| 520 | |
| 521 // Nullable Types | |
| 522 // | |
| 523 if (type.IsGenericType) | |
| 524 { | |
| 525 if (p is Boolean?) return ToChar((Boolean?) p); | |
| 526 if (p is Byte?) return ToChar((Byte?) p); | |
| 527 if (p is Char?) return ToChar((Char?) p); | |
| 528 if (p is Decimal?) return ToChar((Decimal?) p); | |
| 529 if (p is Double?) return ToChar((Double?) p); | |
| 530 if (p is Int16?) return ToChar((Int16?) p); | |
| 531 if (p is Int32?) return ToChar((Int32?) p); | |
| 532 if (p is Int64?) return ToChar((Int64?) p); | |
| 533 if (p is SByte?) return ToChar((SByte?) p); | |
| 534 if (p is Single?) return ToChar((Single?) p); | |
| 535 if (p is UInt16?) return ToChar((UInt16?) p); | |
| 536 if (p is UInt32?) return ToChar((UInt32?) p); | |
| 537 if (p is UInt64?) return ToChar((UInt64?) p); | |
| 538 } | |
| 539 | |
| 540 // Other Types | |
| 541 // | |
| 542 if (p is Binary) return ToChar((Binary) p); | |
| 543 if (p is Byte[]) return ToChar((Byte[]) p); | |
| 544 | |
| 545 #if !SILVERLIGHT | |
| 546 | |
| 547 // Sql Types | |
| 548 // | |
| 549 if (p is INullable) | |
| 550 { | |
| 551 if (p is SqlBoolean) return ToChar((SqlBoolean)p); | |
| 552 if (p is SqlByte) return ToChar((SqlByte) p); | |
| 553 if (p is SqlDecimal) return ToChar((SqlDecimal)p); | |
| 554 if (p is SqlDouble) return ToChar((SqlDouble) p); | |
| 555 if (p is SqlInt16) return ToChar((SqlInt16) p); | |
| 556 if (p is SqlInt32) return ToChar((SqlInt32) p); | |
| 557 if (p is SqlInt64) return ToChar((SqlInt64) p); | |
| 558 if (p is SqlMoney) return ToChar((SqlMoney) p); | |
| 559 if (p is SqlSingle) return ToChar((SqlSingle) p); | |
| 560 if (p is SqlString) return ToChar((SqlString) p); | |
| 561 } | |
| 562 | |
| 563 #endif | |
| 564 | |
| 565 if (p is IConvertible) return ((IConvertible)p).ToChar(null); | |
| 566 | |
| 567 throw CreateInvalidCastException(p.GetType(), typeof(Char)); | |
| 568 } | |
| 569 | |
| 570 #endregion | |
| 571 | |
| 572 #region DateTime | |
| 573 | |
| 574 // Simple Types | |
| 575 // | |
| 576 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 577 public static DateTime ToDateTime(DateTimeOffset p) { return p.LocalDateTime; } | |
| 578 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 579 public static DateTime ToDateTime(Double p) { return DateTime.MinValue + TimeSpan.FromDays (p); } | |
| 580 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 581 public static DateTime ToDateTime(Int64 p) { return DateTime.MinValue + TimeSpan.FromTicks(p); } | |
| 582 /// <summary>Converts the value from <c>String</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 583 public static DateTime ToDateTime(String p) { return p == null ? Configuration.NullableValues.DateTime : DateTime.Parse(p, null, DateTimeStyles.NoCurrentDateDefault); } | |
| 584 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 585 public static DateTime ToDateTime(TimeSpan p) { return DateTime.MinValue + p; } | |
| 586 | |
| 587 // Nullable Types | |
| 588 // | |
| 589 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 590 public static DateTime ToDateTime(DateTime? p) { return p.HasValue ? p.Value : Configuration.NullableValues.DateTime; } | |
| 591 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 592 public static DateTime ToDateTime(DateTimeOffset? p) { return p.HasValue ? p.Value.LocalDateTime : Configuration.NullableValues.DateTime; } | |
| 593 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 594 public static DateTime ToDateTime(Double? p) { return p.HasValue ? DateTime.MinValue + TimeSpan.FromDays (p.Value): Configuration.NullableValues.DateTime; } | |
| 595 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 596 public static DateTime ToDateTime(Int64? p) { return p.HasValue ? DateTime.MinValue + TimeSpan.FromTicks(p.Value): Configuration.NullableValues.DateTime; } | |
| 597 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 598 public static DateTime ToDateTime(TimeSpan? p) { return p.HasValue ? DateTime.MinValue + p.Value : Configuration.NullableValues.DateTime; } | |
| 599 | |
| 600 // Other Types | |
| 601 // | |
| 602 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 603 public static DateTime ToDateTime(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.DateTime : DateTime.FromBinary(ToInt64(p.ToArray())); } | |
| 604 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 605 public static DateTime ToDateTime(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.DateTime : DateTime.FromBinary(ToInt64(p)); } | |
| 606 | |
| 607 #if !SILVERLIGHT | |
| 608 | |
| 609 // Sql Types | |
| 610 // | |
| 611 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 612 public static DateTime ToDateTime(SqlDateTime p) { return p.IsNull ? Configuration.NullableValues.DateTime : p.Value; } | |
| 613 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 614 public static DateTime ToDateTime(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.DateTime : DateTime.MinValue + TimeSpan.FromDays (p.Value); } | |
| 615 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 616 public static DateTime ToDateTime(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.DateTime : DateTime.MinValue + TimeSpan.FromTicks(p.Value); } | |
| 617 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 618 public static DateTime ToDateTime(SqlString p) { return p.IsNull ? Configuration.NullableValues.DateTime : ToDateTime(p.Value); } | |
| 619 | |
| 620 #endif | |
| 621 | |
| 622 // From Object | |
| 623 // | |
| 624 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>DateTime</c> value.</summary> | |
| 625 public static DateTime ToDateTime(object p) | |
| 626 { | |
| 627 if (p == null) return Configuration.NullableValues.DateTime; | |
| 628 | |
| 629 var type = p.GetType(); | |
| 630 | |
| 631 // Primitive types | |
| 632 // | |
| 633 switch (Type.GetTypeCode(type)) | |
| 634 { | |
| 635 case TypeCode.DBNull : return Configuration.NullableValues.DateTime; | |
| 636 case TypeCode.DateTime : return (DateTime)p; | |
| 637 case TypeCode.String : return ToDateTime((String) p); | |
| 638 case TypeCode.Int64 : return ToDateTime((Int64) p); | |
| 639 case TypeCode.Double : return ToDateTime((Double) p); | |
| 640 } | |
| 641 | |
| 642 // Simple Types | |
| 643 // | |
| 644 if (p is DateTimeOffset) return ToDateTime((DateTimeOffset) p); | |
| 645 if (p is TimeSpan) return ToDateTime((TimeSpan) p); | |
| 646 | |
| 647 // Nullable Types | |
| 648 // | |
| 649 if (type.IsGenericType) | |
| 650 { | |
| 651 if (p is DateTime?) return ToDateTime((DateTime?) p); | |
| 652 if (p is DateTimeOffset?) return ToDateTime((DateTimeOffset?)p); | |
| 653 if (p is Double?) return ToDateTime((Double?) p); | |
| 654 if (p is Int64?) return ToDateTime((Int64?) p); | |
| 655 if (p is TimeSpan?) return ToDateTime((TimeSpan?) p); | |
| 656 } | |
| 657 | |
| 658 // Other Types | |
| 659 // | |
| 660 if (p is Binary) return ToDateTime((Binary) p); | |
| 661 if (p is Byte[]) return ToDateTime((Byte[]) p); | |
| 662 | |
| 663 #if !SILVERLIGHT | |
| 664 | |
| 665 // Sql Types | |
| 666 // | |
| 667 if (p is INullable) | |
| 668 { | |
| 669 if (p is SqlDateTime) return ToDateTime((SqlDateTime) p); | |
| 670 if (p is SqlDouble) return ToDateTime((SqlDouble) p); | |
| 671 if (p is SqlInt64) return ToDateTime((SqlInt64) p); | |
| 672 if (p is SqlString) return ToDateTime((SqlString) p); | |
| 673 } | |
| 674 | |
| 675 #endif | |
| 676 | |
| 677 if (p is IConvertible) return ((IConvertible)p).ToDateTime(null); | |
| 678 | |
| 679 throw CreateInvalidCastException(p.GetType(), typeof(DateTime)); | |
| 680 } | |
| 681 | |
| 682 #endregion | |
| 683 | |
| 684 #region DateTimeOffset | |
| 685 | |
| 686 // Simple Types | |
| 687 // | |
| 688 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 689 public static DateTimeOffset ToDateTimeOffset(DateTime p) { return p; } | |
| 690 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 691 public static DateTimeOffset ToDateTimeOffset(Double p) { return DateTimeOffset.MinValue + TimeSpan.FromDays (p); } | |
| 692 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 693 public static DateTimeOffset ToDateTimeOffset(Int64 p) { return DateTimeOffset.MinValue + TimeSpan.FromTicks(p); } | |
| 694 /// <summary>Converts the value from <c>String</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 695 public static DateTimeOffset ToDateTimeOffset(String p) { return p == null? DateTimeOffset.MinValue : DateTimeOffset.Parse(p); } | |
| 696 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 697 public static DateTimeOffset ToDateTimeOffset(TimeSpan p) { return DateTimeOffset.MinValue + p; } | |
| 698 | |
| 699 // Nullable Types | |
| 700 // | |
| 701 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 702 public static DateTimeOffset ToDateTimeOffset(DateTime? p) { return p.HasValue ? p.Value : DateTimeOffset.MinValue; } | |
| 703 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 704 public static DateTimeOffset ToDateTimeOffset(DateTimeOffset? p) { return p.HasValue ? p.Value : DateTimeOffset.MinValue; } | |
| 705 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 706 public static DateTimeOffset ToDateTimeOffset(Double? p) { return p.HasValue ? DateTimeOffset.MinValue + TimeSpan.FromDays (p.Value): DateTimeOffset.MinValue; } | |
| 707 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 708 public static DateTimeOffset ToDateTimeOffset(Int64? p) { return p.HasValue ? DateTimeOffset.MinValue + TimeSpan.FromTicks(p.Value): DateTimeOffset.MinValue; } | |
| 709 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 710 public static DateTimeOffset ToDateTimeOffset(TimeSpan? p) { return p.HasValue ? DateTimeOffset.MinValue + p.Value : DateTimeOffset.MinValue; } | |
| 711 | |
| 712 // Other Types | |
| 713 // | |
| 714 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 715 public static DateTimeOffset ToDateTimeOffset(Binary p) { return p == null || p.Length == 0 ? DateTimeOffset.MinValue : new DateTimeOffset(ToDateTime(p.ToArray())); } | |
| 716 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 717 public static DateTimeOffset ToDateTimeOffset(Byte[] p) { return p == null || p.Length == 0 ? DateTimeOffset.MinValue : new DateTimeOffset(ToDateTime(p)); } | |
| 718 | |
| 719 #if !SILVERLIGHT | |
| 720 | |
| 721 // Sql Types | |
| 722 // | |
| 723 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 724 public static DateTimeOffset ToDateTimeOffset(SqlDateTime p) { return p.IsNull ? DateTimeOffset.MinValue : p.Value; } | |
| 725 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 726 public static DateTimeOffset ToDateTimeOffset(SqlDouble p) { return p.IsNull ? DateTimeOffset.MinValue : DateTimeOffset.MinValue + TimeSpan.FromDays (p.Value); } | |
| 727 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 728 public static DateTimeOffset ToDateTimeOffset(SqlInt64 p) { return p.IsNull ? DateTimeOffset.MinValue : DateTimeOffset.MinValue + TimeSpan.FromTicks(p.Value); } | |
| 729 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 730 public static DateTimeOffset ToDateTimeOffset(SqlString p) { return p.IsNull ? DateTimeOffset.MinValue : ToDateTimeOffset(p.Value); } | |
| 731 | |
| 732 #endif | |
| 733 | |
| 734 // From Object | |
| 735 // | |
| 736 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>DateTimeOffset</c> value.</summary> | |
| 737 public static DateTimeOffset ToDateTimeOffset(object p) | |
| 738 { | |
| 739 if (p == null) return DateTimeOffset.MinValue; | |
| 740 | |
| 741 if (p is DateTimeOffset) return (DateTimeOffset)p; | |
| 742 | |
| 743 var type = p.GetType(); | |
| 744 | |
| 745 // Primitive types | |
| 746 // | |
| 747 switch (Type.GetTypeCode(type)) | |
| 748 { | |
| 749 case TypeCode.DBNull : return DateTimeOffset.MinValue; | |
| 750 case TypeCode.Int64 : return ToDateTimeOffset((Int64) p); | |
| 751 case TypeCode.Double : return ToDateTimeOffset((Double) p); | |
| 752 case TypeCode.DateTime : return ToDateTimeOffset((DateTime) p); | |
| 753 case TypeCode.String : return ToDateTimeOffset((String) p); | |
| 754 } | |
| 755 | |
| 756 // Simple Types | |
| 757 // | |
| 758 if (p is TimeSpan) return ToDateTimeOffset((TimeSpan) p); | |
| 759 | |
| 760 // Nullable Types | |
| 761 // | |
| 762 if (type.IsGenericType) | |
| 763 { | |
| 764 if (p is DateTime?) return ToDateTimeOffset((DateTime?) p); | |
| 765 if (p is DateTimeOffset?) return ToDateTimeOffset((DateTimeOffset?)p); | |
| 766 if (p is Double?) return ToDateTimeOffset((Double?) p); | |
| 767 if (p is Int64?) return ToDateTimeOffset((Int64?) p); | |
| 768 if (p is TimeSpan?) return ToDateTimeOffset((TimeSpan?) p); | |
| 769 } | |
| 770 | |
| 771 // Other Types | |
| 772 // | |
| 773 if (p is Binary) return ToDateTimeOffset((Binary) p); | |
| 774 if (p is Byte[]) return ToDateTimeOffset((Byte[]) p); | |
| 775 | |
| 776 #if !SILVERLIGHT | |
| 777 | |
| 778 // Sql Types | |
| 779 // | |
| 780 if (p is INullable) | |
| 781 { | |
| 782 if (p is SqlDateTime) return ToDateTimeOffset((SqlDateTime) p); | |
| 783 if (p is SqlDouble) return ToDateTimeOffset((SqlDouble) p); | |
| 784 if (p is SqlInt64) return ToDateTimeOffset((SqlInt64) p); | |
| 785 if (p is SqlString) return ToDateTimeOffset((SqlString) p); | |
| 786 } | |
| 787 | |
| 788 #endif | |
| 789 | |
| 790 throw CreateInvalidCastException(p.GetType(), typeof(DateTimeOffset)); | |
| 791 } | |
| 792 | |
| 793 #endregion | |
| 794 | |
| 795 #region Decimal | |
| 796 | |
| 797 // Simple Types | |
| 798 // | |
| 799 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 800 public static Decimal ToDecimal(Boolean p) { return p ? (Decimal)1 : (Decimal)0; } | |
| 801 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 802 public static Decimal ToDecimal(Byte p) { return p; } | |
| 803 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 804 public static Decimal ToDecimal(Char p) { return p; } | |
| 805 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 806 public static Decimal ToDecimal(Double p) { return checked((Decimal)p); } | |
| 807 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 808 public static Decimal ToDecimal(Int16 p) { return p; } | |
| 809 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 810 public static Decimal ToDecimal(Int32 p) { return p; } | |
| 811 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 812 public static Decimal ToDecimal(Int64 p) { return p; } | |
| 813 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 814 [CLSCompliant(false)] | |
| 815 public static Decimal ToDecimal(SByte p) { return p; } | |
| 816 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 817 public static Decimal ToDecimal(Single p) { return checked((Decimal)p); } | |
| 818 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 819 public static Decimal ToDecimal(String p) { return p == null? Configuration.NullableValues.Decimal : Decimal.Parse(p); } | |
| 820 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 821 [CLSCompliant(false)] | |
| 822 public static Decimal ToDecimal(UInt16 p) { return p; } | |
| 823 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 824 [CLSCompliant(false)] | |
| 825 public static Decimal ToDecimal(UInt32 p) { return p; } | |
| 826 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 827 [CLSCompliant(false)] | |
| 828 public static Decimal ToDecimal(UInt64 p) { return p; } | |
| 829 | |
| 830 // Nullable Types | |
| 831 // | |
| 832 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 833 public static Decimal ToDecimal(Boolean? p) { return p.HasValue && p.Value ? (Decimal)1: (Decimal)0; } | |
| 834 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 835 public static Decimal ToDecimal(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 836 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 837 public static Decimal ToDecimal(Char? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 838 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 839 public static Decimal ToDecimal(Decimal? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 840 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 841 public static Decimal ToDecimal(Double? p) { return p.HasValue ? checked((Decimal)p.Value) : Configuration.NullableValues.Decimal; } | |
| 842 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 843 public static Decimal ToDecimal(Int16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 844 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 845 public static Decimal ToDecimal(Int32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 846 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 847 public static Decimal ToDecimal(Int64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 848 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 849 [CLSCompliant(false)] | |
| 850 public static Decimal ToDecimal(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 851 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 852 public static Decimal ToDecimal(Single? p) { return p.HasValue ? checked((Decimal)p.Value) : Configuration.NullableValues.Decimal; } | |
| 853 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 854 [CLSCompliant(false)] | |
| 855 public static Decimal ToDecimal(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 856 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 857 [CLSCompliant(false)] | |
| 858 public static Decimal ToDecimal(UInt32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 859 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 860 [CLSCompliant(false)] | |
| 861 public static Decimal ToDecimal(UInt64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Decimal; } | |
| 862 | |
| 863 #if !SILVERLIGHT | |
| 864 | |
| 865 // Sql Types | |
| 866 // | |
| 867 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 868 public static Decimal ToDecimal(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Decimal : ToDecimal(p.Value); } | |
| 869 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 870 public static Decimal ToDecimal(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Decimal : p.Value; } | |
| 871 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 872 public static Decimal ToDecimal(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Decimal : p.Value; } | |
| 873 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 874 public static Decimal ToDecimal(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Decimal : ToDecimal(p.Value); } | |
| 875 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 876 public static Decimal ToDecimal(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Decimal : p.Value; } | |
| 877 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 878 public static Decimal ToDecimal(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Decimal : p.Value; } | |
| 879 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 880 public static Decimal ToDecimal(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Decimal : p.Value; } | |
| 881 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 882 public static Decimal ToDecimal(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Decimal : p.Value; } | |
| 883 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 884 public static Decimal ToDecimal(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Decimal : ToDecimal(p.Value); } | |
| 885 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 886 public static Decimal ToDecimal(SqlString p) { return p.IsNull ? Configuration.NullableValues.Decimal : ToDecimal(p.Value); } | |
| 887 | |
| 888 #endif | |
| 889 | |
| 890 // From Object | |
| 891 // | |
| 892 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Decimal</c> value.</summary> | |
| 893 public static Decimal ToDecimal(object p) | |
| 894 { | |
| 895 if (p == null) return Configuration.NullableValues.Decimal; | |
| 896 | |
| 897 var type = p.GetType(); | |
| 898 | |
| 899 // Primitive types | |
| 900 // | |
| 901 switch (Type.GetTypeCode(type)) | |
| 902 { | |
| 903 case TypeCode.DBNull : return Configuration.NullableValues.Decimal; | |
| 904 case TypeCode.Decimal : return (Decimal)p; | |
| 905 case TypeCode.SByte : return ToDecimal((SByte) p); | |
| 906 case TypeCode.Int16 : return ToDecimal((Int16) p); | |
| 907 case TypeCode.Int32 : return ToDecimal((Int32) p); | |
| 908 case TypeCode.Int64 : return ToDecimal((Int64) p); | |
| 909 case TypeCode.Byte : return ToDecimal((Byte) p); | |
| 910 case TypeCode.UInt16 : return ToDecimal((UInt16) p); | |
| 911 case TypeCode.UInt32 : return ToDecimal((UInt32) p); | |
| 912 case TypeCode.Char : return ToDecimal((Char) p); | |
| 913 case TypeCode.UInt64 : return ToDecimal((UInt64) p); | |
| 914 case TypeCode.Single : return ToDecimal((Single) p); | |
| 915 case TypeCode.Double : return ToDecimal((Double) p); | |
| 916 case TypeCode.String : return ToDecimal((String) p); | |
| 917 case TypeCode.Boolean : return ToDecimal((Boolean)p); | |
| 918 } | |
| 919 | |
| 920 // Nullable Types | |
| 921 // | |
| 922 if (type.IsGenericType) | |
| 923 { | |
| 924 if (p is Boolean?) return ToDecimal((Boolean?) p); | |
| 925 if (p is Byte?) return ToDecimal((Byte?) p); | |
| 926 if (p is Char?) return ToDecimal((Char?) p); | |
| 927 if (p is Decimal?) return ToDecimal((Decimal?) p); | |
| 928 if (p is Double?) return ToDecimal((Double?) p); | |
| 929 if (p is Int16?) return ToDecimal((Int16?) p); | |
| 930 if (p is Int32?) return ToDecimal((Int32?) p); | |
| 931 if (p is Int64?) return ToDecimal((Int64?) p); | |
| 932 if (p is SByte?) return ToDecimal((SByte?) p); | |
| 933 if (p is Single?) return ToDecimal((Single?) p); | |
| 934 if (p is UInt16?) return ToDecimal((UInt16?) p); | |
| 935 if (p is UInt32?) return ToDecimal((UInt32?) p); | |
| 936 if (p is UInt64?) return ToDecimal((UInt64?) p); | |
| 937 } | |
| 938 | |
| 939 // Other Types | |
| 940 // | |
| 941 if (p is Binary) return ToDecimal((Binary) p); | |
| 942 if (p is Byte[]) return ToDecimal((Byte[]) p); | |
| 943 | |
| 944 #if !SILVERLIGHT | |
| 945 | |
| 946 // Sql Types | |
| 947 // | |
| 948 if (p is INullable) | |
| 949 { | |
| 950 if (p is SqlBoolean) return ToDecimal((SqlBoolean)p); | |
| 951 if (p is SqlByte) return ToDecimal((SqlByte) p); | |
| 952 if (p is SqlDecimal) return ToDecimal((SqlDecimal)p); | |
| 953 if (p is SqlDouble) return ToDecimal((SqlDouble) p); | |
| 954 if (p is SqlInt16) return ToDecimal((SqlInt16) p); | |
| 955 if (p is SqlInt32) return ToDecimal((SqlInt32) p); | |
| 956 if (p is SqlInt64) return ToDecimal((SqlInt64) p); | |
| 957 if (p is SqlMoney) return ToDecimal((SqlMoney) p); | |
| 958 if (p is SqlSingle) return ToDecimal((SqlSingle) p); | |
| 959 if (p is SqlString) return ToDecimal((SqlString) p); | |
| 960 } | |
| 961 | |
| 962 #endif | |
| 963 | |
| 964 if (p is IConvertible) return ((IConvertible)p).ToDecimal(null); | |
| 965 | |
| 966 throw CreateInvalidCastException(p.GetType(), typeof(Decimal)); | |
| 967 } | |
| 968 | |
| 969 #endregion | |
| 970 | |
| 971 #region Double | |
| 972 | |
| 973 // Simple Types | |
| 974 // | |
| 975 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Double</c> value.</summary> | |
| 976 public static Double ToDouble(Boolean p) { return p ? (Double)1 : (Double)0; } | |
| 977 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Double</c> value.</summary> | |
| 978 public static Double ToDouble(Byte p) { return p; } | |
| 979 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Double</c> value.</summary> | |
| 980 public static Double ToDouble(Char p) { return p; } | |
| 981 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>Double</c> value.</summary> | |
| 982 public static Double ToDouble(DateTime p) { return (p - DateTime.MinValue).TotalDays; } | |
| 983 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>Double</c> value.</summary> | |
| 984 public static Double ToDouble(DateTimeOffset p) { return (p - DateTimeOffset.MinValue).TotalDays; } | |
| 985 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Double</c> value.</summary> | |
| 986 public static Double ToDouble(Decimal p) { return checked((Double)p); } | |
| 987 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Double</c> value.</summary> | |
| 988 public static Double ToDouble(Int16 p) { return p; } | |
| 989 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Double</c> value.</summary> | |
| 990 public static Double ToDouble(Int32 p) { return p; } | |
| 991 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Double</c> value.</summary> | |
| 992 public static Double ToDouble(Int64 p) { return p; } | |
| 993 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Double</c> value.</summary> | |
| 994 [CLSCompliant(false)] | |
| 995 public static Double ToDouble(SByte p) { return p; } | |
| 996 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Double</c> value.</summary> | |
| 997 public static Double ToDouble(Single p) { return p; } | |
| 998 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Double</c> value.</summary> | |
| 999 public static Double ToDouble(String p) { return p == null? Configuration.NullableValues.Double : Double.Parse(p); } | |
| 1000 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>Double</c> value.</summary> | |
| 1001 public static Double ToDouble(TimeSpan p) { return p.TotalDays; } | |
| 1002 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Double</c> value.</summary> | |
| 1003 [CLSCompliant(false)] | |
| 1004 public static Double ToDouble(UInt16 p) { return p; } | |
| 1005 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Double</c> value.</summary> | |
| 1006 [CLSCompliant(false)] | |
| 1007 public static Double ToDouble(UInt32 p) { return p; } | |
| 1008 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Double</c> value.</summary> | |
| 1009 [CLSCompliant(false)] | |
| 1010 public static Double ToDouble(UInt64 p) { return p; } | |
| 1011 | |
| 1012 // Nullable Types | |
| 1013 // | |
| 1014 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1015 public static Double ToDouble(Boolean? p) { return p.HasValue && p.Value ? (Double)1: (Double)0; } | |
| 1016 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1017 public static Double ToDouble(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1018 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1019 public static Double ToDouble(Char? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1020 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1021 public static Double ToDouble(DateTime? p) { return p.HasValue ? (p.Value - DateTime.MinValue).TotalDays : Configuration.NullableValues.Double; } | |
| 1022 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1023 public static Double ToDouble(DateTimeOffset? p) { return p.HasValue ? (p.Value - DateTimeOffset.MinValue).TotalDays : Configuration.NullableValues.Double; } | |
| 1024 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1025 public static Double ToDouble(Decimal? p) { return p.HasValue ? checked((Double)p.Value) : Configuration.NullableValues.Double; } | |
| 1026 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1027 public static Double ToDouble(Double? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1028 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1029 public static Double ToDouble(Int16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1030 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1031 public static Double ToDouble(Int32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1032 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1033 public static Double ToDouble(Int64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1034 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1035 [CLSCompliant(false)] | |
| 1036 public static Double ToDouble(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1037 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1038 public static Double ToDouble(Single? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1039 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1040 public static Double ToDouble(TimeSpan? p) { return p.HasValue ? p.Value.TotalDays : Configuration.NullableValues.Double; } | |
| 1041 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1042 [CLSCompliant(false)] | |
| 1043 public static Double ToDouble(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1044 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1045 [CLSCompliant(false)] | |
| 1046 public static Double ToDouble(UInt32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1047 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Double</c> value.</summary> | |
| 1048 [CLSCompliant(false)] | |
| 1049 public static Double ToDouble(UInt64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Double; } | |
| 1050 | |
| 1051 // Other Types | |
| 1052 // | |
| 1053 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Double</c> value.</summary> | |
| 1054 public static Double ToDouble(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Double : BitConverter.ToDouble(p.ToArray(), 0); } | |
| 1055 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Double</c> value.</summary> | |
| 1056 public static Double ToDouble(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Double : BitConverter.ToDouble(p, 0); } | |
| 1057 | |
| 1058 #if !SILVERLIGHT | |
| 1059 | |
| 1060 // Sql Types | |
| 1061 // | |
| 1062 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Double</c> value.</summary> | |
| 1063 public static Double ToDouble(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Double : ToDouble(p.Value); } | |
| 1064 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Double</c> value.</summary> | |
| 1065 public static Double ToDouble(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Double : p.Value; } | |
| 1066 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>Double</c> value.</summary> | |
| 1067 public static Double ToDouble(SqlDateTime p) { return p.IsNull ? Configuration.NullableValues.Double : ToDouble(p.Value); } | |
| 1068 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Double</c> value.</summary> | |
| 1069 public static Double ToDouble(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Double : ToDouble(p.Value); } | |
| 1070 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Double</c> value.</summary> | |
| 1071 public static Double ToDouble(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Double : p.Value; } | |
| 1072 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Double</c> value.</summary> | |
| 1073 public static Double ToDouble(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Double : p.Value; } | |
| 1074 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Double</c> value.</summary> | |
| 1075 public static Double ToDouble(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Double : p.Value; } | |
| 1076 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Double</c> value.</summary> | |
| 1077 public static Double ToDouble(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Double : p.Value; } | |
| 1078 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Double</c> value.</summary> | |
| 1079 public static Double ToDouble(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Double : ToDouble(p.Value); } | |
| 1080 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Double</c> value.</summary> | |
| 1081 public static Double ToDouble(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Double : p.Value; } | |
| 1082 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Double</c> value.</summary> | |
| 1083 public static Double ToDouble(SqlString p) { return p.IsNull ? Configuration.NullableValues.Double : ToDouble(p.Value); } | |
| 1084 | |
| 1085 #endif | |
| 1086 | |
| 1087 // From Object | |
| 1088 // | |
| 1089 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Double</c> value.</summary> | |
| 1090 public static Double ToDouble(object p) | |
| 1091 { | |
| 1092 if (p == null) return Configuration.NullableValues.Double; | |
| 1093 | |
| 1094 var type = p.GetType(); | |
| 1095 | |
| 1096 // Primitive types | |
| 1097 // | |
| 1098 switch (Type.GetTypeCode(type)) | |
| 1099 { | |
| 1100 case TypeCode.DBNull : return Configuration.NullableValues.Double; | |
| 1101 case TypeCode.Double : return (Double)p; | |
| 1102 case TypeCode.DateTime : return ToDouble((DateTime)p); | |
| 1103 case TypeCode.SByte : return ToDouble((SByte) p); | |
| 1104 case TypeCode.Int16 : return ToDouble((Int16) p); | |
| 1105 case TypeCode.Int32 : return ToDouble((Int32) p); | |
| 1106 case TypeCode.Int64 : return ToDouble((Int64) p); | |
| 1107 case TypeCode.Byte : return ToDouble((Byte) p); | |
| 1108 case TypeCode.UInt16 : return ToDouble((UInt16) p); | |
| 1109 case TypeCode.UInt32 : return ToDouble((UInt32) p); | |
| 1110 case TypeCode.Char : return ToDouble((Char) p); | |
| 1111 case TypeCode.UInt64 : return ToDouble((UInt64) p); | |
| 1112 case TypeCode.Single : return ToDouble((Single) p); | |
| 1113 case TypeCode.Decimal : return ToDouble((Decimal) p); | |
| 1114 case TypeCode.String : return ToDouble((String) p); | |
| 1115 case TypeCode.Boolean : return ToDouble((Boolean) p); | |
| 1116 } | |
| 1117 | |
| 1118 // Simple Types | |
| 1119 // | |
| 1120 if (p is DateTimeOffset) return ToDouble((DateTimeOffset) p); | |
| 1121 if (p is TimeSpan) return ToDouble((TimeSpan) p); | |
| 1122 | |
| 1123 // Nullable Types | |
| 1124 // | |
| 1125 if (type.IsGenericType) | |
| 1126 { | |
| 1127 if (p is Boolean?) return ToDouble((Boolean?) p); | |
| 1128 if (p is Byte?) return ToDouble((Byte?) p); | |
| 1129 if (p is Char?) return ToDouble((Char?) p); | |
| 1130 if (p is DateTime?) return ToDouble((DateTime?) p); | |
| 1131 if (p is DateTimeOffset?) return ToDouble((DateTimeOffset?)p); | |
| 1132 if (p is Decimal?) return ToDouble((Decimal?) p); | |
| 1133 if (p is Double?) return ToDouble((Double?) p); | |
| 1134 if (p is Int16?) return ToDouble((Int16?) p); | |
| 1135 if (p is Int32?) return ToDouble((Int32?) p); | |
| 1136 if (p is Int64?) return ToDouble((Int64?) p); | |
| 1137 if (p is SByte?) return ToDouble((SByte?) p); | |
| 1138 if (p is Single?) return ToDouble((Single?) p); | |
| 1139 if (p is TimeSpan?) return ToDouble((TimeSpan?) p); | |
| 1140 if (p is UInt16?) return ToDouble((UInt16?) p); | |
| 1141 if (p is UInt32?) return ToDouble((UInt32?) p); | |
| 1142 if (p is UInt64?) return ToDouble((UInt64?) p); | |
| 1143 } | |
| 1144 | |
| 1145 // Other Types | |
| 1146 // | |
| 1147 if (p is Binary) return ToDouble((Binary) p); | |
| 1148 if (p is Byte[]) return ToDouble((Byte[]) p); | |
| 1149 | |
| 1150 #if !SILVERLIGHT | |
| 1151 | |
| 1152 // Sql Types | |
| 1153 // | |
| 1154 if (p is INullable) | |
| 1155 { | |
| 1156 if (p is SqlBoolean) return ToDouble((SqlBoolean) p); | |
| 1157 if (p is SqlByte) return ToDouble((SqlByte) p); | |
| 1158 if (p is SqlDateTime) return ToDouble((SqlDateTime) p); | |
| 1159 if (p is SqlDecimal) return ToDouble((SqlDecimal) p); | |
| 1160 if (p is SqlDouble) return ToDouble((SqlDouble) p); | |
| 1161 if (p is SqlInt16) return ToDouble((SqlInt16) p); | |
| 1162 if (p is SqlInt32) return ToDouble((SqlInt32) p); | |
| 1163 if (p is SqlInt64) return ToDouble((SqlInt64) p); | |
| 1164 if (p is SqlMoney) return ToDouble((SqlMoney) p); | |
| 1165 if (p is SqlSingle) return ToDouble((SqlSingle) p); | |
| 1166 if (p is SqlString) return ToDouble((SqlString) p); | |
| 1167 } | |
| 1168 | |
| 1169 #endif | |
| 1170 | |
| 1171 if (p is IConvertible) return ((IConvertible)p).ToDouble(null); | |
| 1172 | |
| 1173 throw CreateInvalidCastException(p.GetType(), typeof(Double)); | |
| 1174 } | |
| 1175 | |
| 1176 #endregion | |
| 1177 | |
| 1178 #region Guid | |
| 1179 | |
| 1180 // Simple Types | |
| 1181 // | |
| 1182 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1183 public static Guid ToGuid(String p) { return p == null ? Configuration.NullableValues.Guid : new Guid(p); } | |
| 1184 | |
| 1185 // Nullable Types | |
| 1186 // | |
| 1187 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1188 public static Guid ToGuid(Guid? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Guid; } | |
| 1189 | |
| 1190 // Other Types | |
| 1191 // | |
| 1192 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1193 public static Guid ToGuid(Binary p) { return p == null ? Configuration.NullableValues.Guid : new Guid(p.ToArray()); } | |
| 1194 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1195 public static Guid ToGuid(Byte[] p) { return p == null ? Configuration.NullableValues.Guid : new Guid(p); } | |
| 1196 /// <summary>Converts the value from <c>Type</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1197 public static Guid ToGuid(Type p) { return p == null ? Configuration.NullableValues.Guid : p.GUID; } | |
| 1198 | |
| 1199 #if !SILVERLIGHT | |
| 1200 | |
| 1201 // Sql Types | |
| 1202 // | |
| 1203 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1204 public static Guid ToGuid(SqlBinary p) { return p.IsNull ? Configuration.NullableValues.Guid : p.ToSqlGuid().Value; } | |
| 1205 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1206 public static Guid ToGuid(SqlGuid p) { return p.IsNull ? Configuration.NullableValues.Guid : p.Value; } | |
| 1207 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1208 public static Guid ToGuid(SqlString p) { return p.IsNull ? Configuration.NullableValues.Guid : new Guid(p.Value); } | |
| 1209 | |
| 1210 #endif | |
| 1211 | |
| 1212 // From Object | |
| 1213 // | |
| 1214 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Guid</c> value.</summary> | |
| 1215 public static Guid ToGuid(object p) | |
| 1216 { | |
| 1217 if (p == null) return Configuration.NullableValues.Guid; | |
| 1218 | |
| 1219 if (p is Guid) return (Guid)p; | |
| 1220 | |
| 1221 var type = p.GetType(); | |
| 1222 | |
| 1223 // Primitive types | |
| 1224 // | |
| 1225 switch (Type.GetTypeCode(type)) | |
| 1226 { | |
| 1227 case TypeCode.DBNull : return Configuration.NullableValues.Guid; | |
| 1228 case TypeCode.String : return ToGuid((String)p); | |
| 1229 } | |
| 1230 | |
| 1231 // Nullable Types | |
| 1232 // | |
| 1233 if (type.IsGenericType) | |
| 1234 { | |
| 1235 if (p is Guid?) return ToGuid((Guid?) p); | |
| 1236 } | |
| 1237 | |
| 1238 // Other Types | |
| 1239 // | |
| 1240 if (p is Binary) return ToGuid((Binary) p); | |
| 1241 if (p is Byte[]) return ToGuid((Byte[]) p); | |
| 1242 if (p is Type) return ToGuid((Type) p); | |
| 1243 | |
| 1244 #if !SILVERLIGHT | |
| 1245 | |
| 1246 // Sql Types | |
| 1247 // | |
| 1248 if (p is INullable) | |
| 1249 { | |
| 1250 if (p is SqlBinary) return ToGuid((SqlBinary)p); | |
| 1251 if (p is SqlGuid) return ToGuid((SqlGuid) p); | |
| 1252 if (p is SqlString) return ToGuid((SqlString)p); | |
| 1253 } | |
| 1254 | |
| 1255 #endif | |
| 1256 | |
| 1257 throw CreateInvalidCastException(p.GetType(), typeof(Guid)); | |
| 1258 } | |
| 1259 | |
| 1260 #endregion | |
| 1261 | |
| 1262 #region Int16 | |
| 1263 | |
| 1264 // Simple Types | |
| 1265 // | |
| 1266 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1267 public static Int16 ToInt16(Boolean p) { return p ? (Int16)1 : (Int16)0; } | |
| 1268 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1269 public static Int16 ToInt16(Byte p) { return p; } | |
| 1270 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1271 public static Int16 ToInt16(Char p) { return checked((Int16)p); } | |
| 1272 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1273 public static Int16 ToInt16(Decimal p) { return checked((Int16)p); } | |
| 1274 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1275 public static Int16 ToInt16(Double p) { return checked((Int16)p); } | |
| 1276 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1277 public static Int16 ToInt16(Int32 p) { return checked((Int16)p); } | |
| 1278 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1279 public static Int16 ToInt16(Int64 p) { return checked((Int16)p); } | |
| 1280 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1281 [CLSCompliant(false)] | |
| 1282 public static Int16 ToInt16(SByte p) { return p; } | |
| 1283 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1284 public static Int16 ToInt16(Single p) { return checked((Int16)p); } | |
| 1285 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1286 public static Int16 ToInt16(String p) { return p == null? Configuration.NullableValues.Int16 : Int16.Parse(p); } | |
| 1287 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1288 [CLSCompliant(false)] | |
| 1289 public static Int16 ToInt16(UInt16 p) { return checked((Int16)p); } | |
| 1290 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1291 [CLSCompliant(false)] | |
| 1292 public static Int16 ToInt16(UInt32 p) { return checked((Int16)p); } | |
| 1293 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1294 [CLSCompliant(false)] | |
| 1295 public static Int16 ToInt16(UInt64 p) { return checked((Int16)p); } | |
| 1296 | |
| 1297 // Nullable Types | |
| 1298 // | |
| 1299 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1300 public static Int16 ToInt16(Boolean? p) { return p.HasValue && p.Value ? (Int16)1: (Int16)0; } | |
| 1301 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1302 public static Int16 ToInt16(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int16; } | |
| 1303 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1304 public static Int16 ToInt16(Char? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1305 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1306 public static Int16 ToInt16(Decimal? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1307 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1308 public static Int16 ToInt16(Double? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1309 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1310 public static Int16 ToInt16(Int16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int16; } | |
| 1311 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1312 public static Int16 ToInt16(Int32? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1313 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1314 public static Int16 ToInt16(Int64? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1315 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1316 [CLSCompliant(false)] | |
| 1317 public static Int16 ToInt16(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int16; } | |
| 1318 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1319 public static Int16 ToInt16(Single? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1320 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1321 [CLSCompliant(false)] | |
| 1322 public static Int16 ToInt16(UInt16? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1323 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1324 [CLSCompliant(false)] | |
| 1325 public static Int16 ToInt16(UInt32? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1326 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1327 [CLSCompliant(false)] | |
| 1328 public static Int16 ToInt16(UInt64? p) { return p.HasValue ? checked((Int16)p.Value) : Configuration.NullableValues.Int16; } | |
| 1329 | |
| 1330 // Other Types | |
| 1331 // | |
| 1332 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1333 public static Int16 ToInt16(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Int16 : BitConverter.ToInt16(p.ToArray(), 0); } | |
| 1334 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1335 public static Int16 ToInt16(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Int16 : BitConverter.ToInt16(p, 0); } | |
| 1336 | |
| 1337 #if !SILVERLIGHT | |
| 1338 | |
| 1339 // Sql Types | |
| 1340 // | |
| 1341 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1342 public static Int16 ToInt16(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1343 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1344 public static Int16 ToInt16(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Int16 : p.Value; } | |
| 1345 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1346 public static Int16 ToInt16(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1347 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1348 public static Int16 ToInt16(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1349 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1350 public static Int16 ToInt16(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Int16 : p.Value; } | |
| 1351 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1352 public static Int16 ToInt16(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1353 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1354 public static Int16 ToInt16(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1355 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1356 public static Int16 ToInt16(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1357 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1358 public static Int16 ToInt16(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1359 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1360 public static Int16 ToInt16(SqlString p) { return p.IsNull ? Configuration.NullableValues.Int16 : ToInt16(p.Value); } | |
| 1361 | |
| 1362 #endif | |
| 1363 | |
| 1364 // From Object | |
| 1365 // | |
| 1366 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Int16</c> value.</summary> | |
| 1367 public static Int16 ToInt16(object p) | |
| 1368 { | |
| 1369 if (p == null) return Configuration.NullableValues.Int16; | |
| 1370 | |
| 1371 var type = p.GetType(); | |
| 1372 | |
| 1373 // Primitive types | |
| 1374 // | |
| 1375 switch (Type.GetTypeCode(type)) | |
| 1376 { | |
| 1377 case TypeCode.DBNull : return Configuration.NullableValues.Int16; | |
| 1378 case TypeCode.Int16 : return (Int16)p; | |
| 1379 case TypeCode.SByte : return ToInt16((SByte) p); | |
| 1380 case TypeCode.Byte : return ToInt16((Byte) p); | |
| 1381 case TypeCode.Int32 : return ToInt16((Int32) p); | |
| 1382 case TypeCode.Int64 : return ToInt16((Int64) p); | |
| 1383 case TypeCode.UInt16 : return ToInt16((UInt16) p); | |
| 1384 case TypeCode.UInt32 : return ToInt16((UInt32) p); | |
| 1385 case TypeCode.UInt64 : return ToInt16((UInt64) p); | |
| 1386 case TypeCode.Single : return ToInt16((Single) p); | |
| 1387 case TypeCode.Double : return ToInt16((Double) p); | |
| 1388 case TypeCode.Decimal : return ToInt16((Decimal)p); | |
| 1389 case TypeCode.Char : return ToInt16((Char) p); | |
| 1390 case TypeCode.String : return ToInt16((String) p); | |
| 1391 case TypeCode.Boolean : return ToInt16((Boolean)p); | |
| 1392 } | |
| 1393 | |
| 1394 // Nullable Types | |
| 1395 // | |
| 1396 if (type.IsGenericType) | |
| 1397 { | |
| 1398 if (p is Boolean?) return ToInt16((Boolean?) p); | |
| 1399 if (p is Byte?) return ToInt16((Byte?) p); | |
| 1400 if (p is Char?) return ToInt16((Char?) p); | |
| 1401 if (p is Decimal?) return ToInt16((Decimal?) p); | |
| 1402 if (p is Double?) return ToInt16((Double?) p); | |
| 1403 if (p is Int16?) return ToInt16((Int16?) p); | |
| 1404 if (p is Int32?) return ToInt16((Int32?) p); | |
| 1405 if (p is Int64?) return ToInt16((Int64?) p); | |
| 1406 if (p is SByte?) return ToInt16((SByte?) p); | |
| 1407 if (p is Single?) return ToInt16((Single?) p); | |
| 1408 if (p is UInt16?) return ToInt16((UInt16?) p); | |
| 1409 if (p is UInt32?) return ToInt16((UInt32?) p); | |
| 1410 if (p is UInt64?) return ToInt16((UInt64?) p); | |
| 1411 } | |
| 1412 | |
| 1413 // Other Types | |
| 1414 // | |
| 1415 if (p is Binary) return ToInt16((Binary) p); | |
| 1416 if (p is Byte[]) return ToInt16((Byte[]) p); | |
| 1417 | |
| 1418 #if !SILVERLIGHT | |
| 1419 | |
| 1420 // Sql Types | |
| 1421 // | |
| 1422 if (p is INullable) | |
| 1423 { | |
| 1424 if (p is SqlBoolean) return ToInt16((SqlBoolean)p); | |
| 1425 if (p is SqlByte) return ToInt16((SqlByte) p); | |
| 1426 if (p is SqlDecimal) return ToInt16((SqlDecimal)p); | |
| 1427 if (p is SqlDouble) return ToInt16((SqlDouble) p); | |
| 1428 if (p is SqlInt16) return ToInt16((SqlInt16) p); | |
| 1429 if (p is SqlInt32) return ToInt16((SqlInt32) p); | |
| 1430 if (p is SqlInt64) return ToInt16((SqlInt64) p); | |
| 1431 if (p is SqlMoney) return ToInt16((SqlMoney) p); | |
| 1432 if (p is SqlSingle) return ToInt16((SqlSingle) p); | |
| 1433 if (p is SqlString) return ToInt16((SqlString) p); | |
| 1434 } | |
| 1435 | |
| 1436 #endif | |
| 1437 | |
| 1438 if (p is IConvertible) return ((IConvertible)p).ToInt16(null); | |
| 1439 | |
| 1440 throw CreateInvalidCastException(p.GetType(), typeof(Int16)); | |
| 1441 } | |
| 1442 | |
| 1443 #endregion | |
| 1444 | |
| 1445 #region Int32 | |
| 1446 | |
| 1447 // Simple Types | |
| 1448 // | |
| 1449 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1450 public static Int32 ToInt32(Boolean p) { return p ? (Int32)1 : (Int32)0; } | |
| 1451 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1452 public static Int32 ToInt32(Byte p) { return p; } | |
| 1453 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1454 public static Int32 ToInt32(Char p) { return p; } | |
| 1455 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1456 public static Int32 ToInt32(Decimal p) { return checked((Int32)p); } | |
| 1457 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1458 public static Int32 ToInt32(Double p) { return checked((Int32)p); } | |
| 1459 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1460 public static Int32 ToInt32(Int16 p) { return p; } | |
| 1461 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1462 public static Int32 ToInt32(Int64 p) { return checked((Int32)p); } | |
| 1463 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1464 [CLSCompliant(false)] | |
| 1465 public static Int32 ToInt32(SByte p) { return p; } | |
| 1466 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1467 public static Int32 ToInt32(Single p) { return checked((Int32)p); } | |
| 1468 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1469 public static Int32 ToInt32(String p) { return p == null? Configuration.NullableValues.Int32 : Int32.Parse(p); } | |
| 1470 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1471 [CLSCompliant(false)] | |
| 1472 public static Int32 ToInt32(UInt16 p) { return p; } | |
| 1473 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1474 [CLSCompliant(false)] | |
| 1475 public static Int32 ToInt32(UInt32 p) { return checked((Int32)p); } | |
| 1476 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1477 [CLSCompliant(false)] | |
| 1478 public static Int32 ToInt32(UInt64 p) { return checked((Int32)p); } | |
| 1479 | |
| 1480 // Nullable Types | |
| 1481 // | |
| 1482 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1483 public static Int32 ToInt32(Boolean? p) { return p.HasValue && p.Value ? (Int32)1: (Int32)0; } | |
| 1484 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1485 public static Int32 ToInt32(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int32; } | |
| 1486 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1487 public static Int32 ToInt32(Char? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int32; } | |
| 1488 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1489 public static Int32 ToInt32(Decimal? p) { return p.HasValue ? checked((Int32)p.Value) : Configuration.NullableValues.Int32; } | |
| 1490 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1491 public static Int32 ToInt32(Double? p) { return p.HasValue ? checked((Int32)p.Value) : Configuration.NullableValues.Int32; } | |
| 1492 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1493 public static Int32 ToInt32(Int16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int32; } | |
| 1494 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1495 public static Int32 ToInt32(Int32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int32; } | |
| 1496 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1497 public static Int32 ToInt32(Int64? p) { return p.HasValue ? checked((Int32)p.Value) : Configuration.NullableValues.Int32; } | |
| 1498 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1499 [CLSCompliant(false)] | |
| 1500 public static Int32 ToInt32(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int32; } | |
| 1501 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1502 public static Int32 ToInt32(Single? p) { return p.HasValue ? checked((Int32)p.Value) : Configuration.NullableValues.Int32; } | |
| 1503 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1504 [CLSCompliant(false)] | |
| 1505 public static Int32 ToInt32(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int32; } | |
| 1506 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1507 [CLSCompliant(false)] | |
| 1508 public static Int32 ToInt32(UInt32? p) { return p.HasValue ? checked((Int32)p.Value) : Configuration.NullableValues.Int32; } | |
| 1509 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1510 [CLSCompliant(false)] | |
| 1511 public static Int32 ToInt32(UInt64? p) { return p.HasValue ? checked((Int32)p.Value) : Configuration.NullableValues.Int32; } | |
| 1512 | |
| 1513 // Other Types | |
| 1514 // | |
| 1515 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1516 public static Int32 ToInt32(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Int32 : BitConverter.ToInt32(p.ToArray(), 0); } | |
| 1517 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1518 public static Int32 ToInt32(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Int32 : BitConverter.ToInt32(p, 0); } | |
| 1519 | |
| 1520 #if !SILVERLIGHT | |
| 1521 | |
| 1522 // Sql Types | |
| 1523 // | |
| 1524 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1525 public static Int32 ToInt32(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1526 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1527 public static Int32 ToInt32(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Int32 : p.Value; } | |
| 1528 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1529 public static Int32 ToInt32(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1530 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1531 public static Int32 ToInt32(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1532 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1533 public static Int32 ToInt32(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Int32 : p.Value; } | |
| 1534 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1535 public static Int32 ToInt32(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Int32 : p.Value; } | |
| 1536 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1537 public static Int32 ToInt32(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1538 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1539 public static Int32 ToInt32(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1540 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1541 public static Int32 ToInt32(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1542 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1543 public static Int32 ToInt32(SqlString p) { return p.IsNull ? Configuration.NullableValues.Int32 : ToInt32(p.Value); } | |
| 1544 | |
| 1545 #endif | |
| 1546 | |
| 1547 // From Object | |
| 1548 // | |
| 1549 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Int32</c> value.</summary> | |
| 1550 public static Int32 ToInt32(object p) | |
| 1551 { | |
| 1552 if (p == null) return Configuration.NullableValues.Int32; | |
| 1553 | |
| 1554 var type = p.GetType(); | |
| 1555 | |
| 1556 // Primitive types | |
| 1557 // | |
| 1558 switch (Type.GetTypeCode(type)) | |
| 1559 { | |
| 1560 case TypeCode.DBNull : return Configuration.NullableValues.Int32; | |
| 1561 case TypeCode.Int32 : return (Int32)p; | |
| 1562 case TypeCode.SByte : return ToInt32((SByte) p); | |
| 1563 case TypeCode.Int16 : return ToInt32((Int16) p); | |
| 1564 case TypeCode.Byte : return ToInt32((Byte) p); | |
| 1565 case TypeCode.UInt16 : return ToInt32((UInt16) p); | |
| 1566 case TypeCode.Char : return ToInt32((Char) p); | |
| 1567 case TypeCode.Int64 : return ToInt32((Int64) p); | |
| 1568 case TypeCode.UInt32 : return ToInt32((UInt32) p); | |
| 1569 case TypeCode.UInt64 : return ToInt32((UInt64) p); | |
| 1570 case TypeCode.Single : return ToInt32((Single) p); | |
| 1571 case TypeCode.Double : return ToInt32((Double) p); | |
| 1572 case TypeCode.Decimal : return ToInt32((Decimal)p); | |
| 1573 case TypeCode.String : return ToInt32((String) p); | |
| 1574 case TypeCode.Boolean : return ToInt32((Boolean)p); | |
| 1575 } | |
| 1576 | |
| 1577 // Nullable Types | |
| 1578 // | |
| 1579 if (type.IsGenericType) | |
| 1580 { | |
| 1581 if (p is Boolean?) return ToInt32((Boolean?) p); | |
| 1582 if (p is Byte?) return ToInt32((Byte?) p); | |
| 1583 if (p is Char?) return ToInt32((Char?) p); | |
| 1584 if (p is Decimal?) return ToInt32((Decimal?) p); | |
| 1585 if (p is Double?) return ToInt32((Double?) p); | |
| 1586 if (p is Int16?) return ToInt32((Int16?) p); | |
| 1587 if (p is Int32?) return ToInt32((Int32?) p); | |
| 1588 if (p is Int64?) return ToInt32((Int64?) p); | |
| 1589 if (p is SByte?) return ToInt32((SByte?) p); | |
| 1590 if (p is Single?) return ToInt32((Single?) p); | |
| 1591 if (p is UInt16?) return ToInt32((UInt16?) p); | |
| 1592 if (p is UInt32?) return ToInt32((UInt32?) p); | |
| 1593 if (p is UInt64?) return ToInt32((UInt64?) p); | |
| 1594 } | |
| 1595 | |
| 1596 // Other Types | |
| 1597 // | |
| 1598 if (p is Binary) return ToInt32((Binary) p); | |
| 1599 if (p is Byte[]) return ToInt32((Byte[]) p); | |
| 1600 | |
| 1601 #if !SILVERLIGHT | |
| 1602 | |
| 1603 // Sql Types | |
| 1604 // | |
| 1605 if (p is INullable) | |
| 1606 { | |
| 1607 if (p is SqlBoolean) return ToInt32((SqlBoolean)p); | |
| 1608 if (p is SqlByte) return ToInt32((SqlByte) p); | |
| 1609 if (p is SqlDecimal) return ToInt32((SqlDecimal)p); | |
| 1610 if (p is SqlDouble) return ToInt32((SqlDouble) p); | |
| 1611 if (p is SqlInt16) return ToInt32((SqlInt16) p); | |
| 1612 if (p is SqlInt32) return ToInt32((SqlInt32) p); | |
| 1613 if (p is SqlInt64) return ToInt32((SqlInt64) p); | |
| 1614 if (p is SqlMoney) return ToInt32((SqlMoney) p); | |
| 1615 if (p is SqlSingle) return ToInt32((SqlSingle) p); | |
| 1616 if (p is SqlString) return ToInt32((SqlString) p); | |
| 1617 } | |
| 1618 | |
| 1619 #endif | |
| 1620 | |
| 1621 if (p is IConvertible) return ((IConvertible)p).ToInt32(null); | |
| 1622 | |
| 1623 throw CreateInvalidCastException(p.GetType(), typeof(Int32)); | |
| 1624 } | |
| 1625 | |
| 1626 #endregion | |
| 1627 | |
| 1628 #region Int64 | |
| 1629 | |
| 1630 // Simple Types | |
| 1631 // | |
| 1632 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1633 public static Int64 ToInt64(Boolean p) { return p ? (Int64)1 : (Int64)0; } | |
| 1634 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1635 public static Int64 ToInt64(Byte p) { return p; } | |
| 1636 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1637 public static Int64 ToInt64(Char p) { return p; } | |
| 1638 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1639 public static Int64 ToInt64(DateTime p) { return (p - DateTime.MinValue).Ticks; } | |
| 1640 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1641 public static Int64 ToInt64(DateTimeOffset p) { return (p - DateTime.MinValue).Ticks; } | |
| 1642 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1643 public static Int64 ToInt64(Decimal p) { return checked((Int64)p); } | |
| 1644 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1645 public static Int64 ToInt64(Double p) { return checked((Int64)p); } | |
| 1646 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1647 public static Int64 ToInt64(Int16 p) { return p; } | |
| 1648 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1649 public static Int64 ToInt64(Int32 p) { return p; } | |
| 1650 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1651 [CLSCompliant(false)] | |
| 1652 public static Int64 ToInt64(SByte p) { return p; } | |
| 1653 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1654 public static Int64 ToInt64(Single p) { return checked((Int64)p); } | |
| 1655 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1656 public static Int64 ToInt64(String p) { return p == null? Configuration.NullableValues.Int64 : Int64.Parse(p); } | |
| 1657 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1658 public static Int64 ToInt64(TimeSpan p) { return p.Ticks; } | |
| 1659 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1660 [CLSCompliant(false)] | |
| 1661 public static Int64 ToInt64(UInt16 p) { return p; } | |
| 1662 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1663 [CLSCompliant(false)] | |
| 1664 public static Int64 ToInt64(UInt32 p) { return p; } | |
| 1665 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1666 [CLSCompliant(false)] | |
| 1667 public static Int64 ToInt64(UInt64 p) { return checked((Int64)p); } | |
| 1668 | |
| 1669 // Nullable Types | |
| 1670 // | |
| 1671 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1672 public static Int64 ToInt64(Boolean? p) { return p.HasValue && p.Value ? (Int64)1: (Int64)0; } | |
| 1673 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1674 public static Int64 ToInt64(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1675 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1676 public static Int64 ToInt64(Char? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1677 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1678 public static Int64 ToInt64(DateTime? p) { return p.HasValue ? (p.Value - DateTime.MinValue).Ticks : 0; } | |
| 1679 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1680 public static Int64 ToInt64(DateTimeOffset? p) { return p.HasValue ? (p.Value - DateTime.MinValue).Ticks : 0; } | |
| 1681 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1682 public static Int64 ToInt64(Decimal? p) { return p.HasValue ? checked((Int64)p.Value) : Configuration.NullableValues.Int64; } | |
| 1683 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1684 public static Int64 ToInt64(Double? p) { return p.HasValue ? checked((Int64)p.Value) : Configuration.NullableValues.Int64; } | |
| 1685 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1686 public static Int64 ToInt64(Int16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1687 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1688 public static Int64 ToInt64(Int32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1689 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1690 public static Int64 ToInt64(Int64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1691 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1692 [CLSCompliant(false)] | |
| 1693 public static Int64 ToInt64(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1694 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1695 public static Int64 ToInt64(Single? p) { return p.HasValue ? checked((Int64)p.Value) : Configuration.NullableValues.Int64; } | |
| 1696 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1697 public static Int64 ToInt64(TimeSpan? p) { return p.HasValue ? p.Value.Ticks : 0; } | |
| 1698 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1699 [CLSCompliant(false)] | |
| 1700 public static Int64 ToInt64(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1701 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1702 [CLSCompliant(false)] | |
| 1703 public static Int64 ToInt64(UInt32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Int64; } | |
| 1704 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1705 [CLSCompliant(false)] | |
| 1706 public static Int64 ToInt64(UInt64? p) { return p.HasValue ? checked((Int64)p.Value) : Configuration.NullableValues.Int64; } | |
| 1707 | |
| 1708 // Other Types | |
| 1709 // | |
| 1710 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1711 public static Int64 ToInt64(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Int64 : BitConverter.ToInt64(p.ToArray(), 0); } | |
| 1712 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1713 public static Int64 ToInt64(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Int64 : BitConverter.ToInt64(p, 0); } | |
| 1714 | |
| 1715 #if !SILVERLIGHT | |
| 1716 | |
| 1717 // Sql Types | |
| 1718 // | |
| 1719 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1720 public static Int64 ToInt64(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1721 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1722 public static Int64 ToInt64(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Int64 : p.Value; } | |
| 1723 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1724 public static Int64 ToInt64(SqlDateTime p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1725 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1726 public static Int64 ToInt64(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1727 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1728 public static Int64 ToInt64(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1729 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1730 public static Int64 ToInt64(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Int64 : p.Value; } | |
| 1731 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1732 public static Int64 ToInt64(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Int64 : p.Value; } | |
| 1733 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1734 public static Int64 ToInt64(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Int64 : p.Value; } | |
| 1735 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1736 public static Int64 ToInt64(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1737 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1738 public static Int64 ToInt64(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1739 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1740 public static Int64 ToInt64(SqlString p) { return p.IsNull ? Configuration.NullableValues.Int64 : ToInt64(p.Value); } | |
| 1741 | |
| 1742 #endif | |
| 1743 | |
| 1744 // From Object | |
| 1745 // | |
| 1746 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Int64</c> value.</summary> | |
| 1747 public static Int64 ToInt64(object p) | |
| 1748 { | |
| 1749 if (p == null) return Configuration.NullableValues.Int64; | |
| 1750 | |
| 1751 var type = p.GetType(); | |
| 1752 | |
| 1753 // Primitive types | |
| 1754 // | |
| 1755 switch (Type.GetTypeCode(type)) | |
| 1756 { | |
| 1757 case TypeCode.DBNull : return Configuration.NullableValues.Int64; | |
| 1758 case TypeCode.Int64 : return (Int64)p; | |
| 1759 case TypeCode.DateTime : return ToInt64((DateTime)p); | |
| 1760 case TypeCode.SByte : return ToInt64((SByte) p); | |
| 1761 case TypeCode.Int16 : return ToInt64((Int16) p); | |
| 1762 case TypeCode.Int32 : return ToInt64((Int32) p); | |
| 1763 case TypeCode.Byte : return ToInt64((Byte) p); | |
| 1764 case TypeCode.UInt16 : return ToInt64((UInt16) p); | |
| 1765 case TypeCode.UInt32 : return ToInt64((UInt32) p); | |
| 1766 case TypeCode.Char : return ToInt64((Char) p); | |
| 1767 case TypeCode.UInt64 : return ToInt64((UInt64) p); | |
| 1768 case TypeCode.Single : return ToInt64((Single) p); | |
| 1769 case TypeCode.Double : return ToInt64((Double) p); | |
| 1770 case TypeCode.Decimal : return ToInt64((Decimal) p); | |
| 1771 case TypeCode.String : return ToInt64((String) p); | |
| 1772 case TypeCode.Boolean : return ToInt64((Boolean) p); | |
| 1773 } | |
| 1774 | |
| 1775 // Simple Types | |
| 1776 // | |
| 1777 if (p is DateTimeOffset) return ToInt64((DateTimeOffset) p); | |
| 1778 if (p is TimeSpan) return ToInt64((TimeSpan) p); | |
| 1779 | |
| 1780 // Nullable Types | |
| 1781 // | |
| 1782 if (type.IsGenericType) | |
| 1783 { | |
| 1784 if (p is Boolean?) return ToInt64((Boolean?) p); | |
| 1785 if (p is Byte?) return ToInt64((Byte?) p); | |
| 1786 if (p is Char?) return ToInt64((Char?) p); | |
| 1787 if (p is DateTime?) return ToInt64((DateTime?) p); | |
| 1788 if (p is DateTimeOffset?) return ToInt64((DateTimeOffset?)p); | |
| 1789 if (p is Decimal?) return ToInt64((Decimal?) p); | |
| 1790 if (p is Double?) return ToInt64((Double?) p); | |
| 1791 if (p is Int16?) return ToInt64((Int16?) p); | |
| 1792 if (p is Int32?) return ToInt64((Int32?) p); | |
| 1793 if (p is Int64?) return ToInt64((Int64?) p); | |
| 1794 if (p is SByte?) return ToInt64((SByte?) p); | |
| 1795 if (p is Single?) return ToInt64((Single?) p); | |
| 1796 if (p is TimeSpan?) return ToInt64((TimeSpan?) p); | |
| 1797 if (p is UInt16?) return ToInt64((UInt16?) p); | |
| 1798 if (p is UInt32?) return ToInt64((UInt32?) p); | |
| 1799 if (p is UInt64?) return ToInt64((UInt64?) p); | |
| 1800 } | |
| 1801 | |
| 1802 // Other Types | |
| 1803 // | |
| 1804 if (p is Binary) return ToInt64((Binary) p); | |
| 1805 if (p is Byte[]) return ToInt64((Byte[]) p); | |
| 1806 | |
| 1807 #if !SILVERLIGHT | |
| 1808 | |
| 1809 // Sql Types | |
| 1810 // | |
| 1811 if (p is INullable) | |
| 1812 { | |
| 1813 if (p is SqlBoolean) return ToInt64((SqlBoolean) p); | |
| 1814 if (p is SqlByte) return ToInt64((SqlByte) p); | |
| 1815 if (p is SqlDateTime) return ToInt64((SqlDateTime) p); | |
| 1816 if (p is SqlDecimal) return ToInt64((SqlDecimal) p); | |
| 1817 if (p is SqlDouble) return ToInt64((SqlDouble) p); | |
| 1818 if (p is SqlInt16) return ToInt64((SqlInt16) p); | |
| 1819 if (p is SqlInt32) return ToInt64((SqlInt32) p); | |
| 1820 if (p is SqlInt64) return ToInt64((SqlInt64) p); | |
| 1821 if (p is SqlMoney) return ToInt64((SqlMoney) p); | |
| 1822 if (p is SqlSingle) return ToInt64((SqlSingle) p); | |
| 1823 if (p is SqlString) return ToInt64((SqlString) p); | |
| 1824 } | |
| 1825 | |
| 1826 #endif | |
| 1827 | |
| 1828 if (p is IConvertible) return ((IConvertible)p).ToInt64(null); | |
| 1829 | |
| 1830 throw CreateInvalidCastException(p.GetType(), typeof(Int64)); | |
| 1831 } | |
| 1832 | |
| 1833 #endregion | |
| 1834 | |
| 1835 #region SByte | |
| 1836 | |
| 1837 // Simple Types | |
| 1838 // | |
| 1839 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1840 [CLSCompliant(false)] | |
| 1841 public static SByte ToSByte(Boolean p) { return p ? (SByte)1 : (SByte)0; } | |
| 1842 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1843 [CLSCompliant(false)] | |
| 1844 public static SByte ToSByte(Byte p) { return checked((SByte)p); } | |
| 1845 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1846 [CLSCompliant(false)] | |
| 1847 public static SByte ToSByte(Char p) { return checked((SByte)p); } | |
| 1848 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1849 [CLSCompliant(false)] | |
| 1850 public static SByte ToSByte(Decimal p) { return checked((SByte)p); } | |
| 1851 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1852 [CLSCompliant(false)] | |
| 1853 public static SByte ToSByte(Double p) { return checked((SByte)p); } | |
| 1854 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1855 [CLSCompliant(false)] | |
| 1856 public static SByte ToSByte(Int16 p) { return checked((SByte)p); } | |
| 1857 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1858 [CLSCompliant(false)] | |
| 1859 public static SByte ToSByte(Int32 p) { return checked((SByte)p); } | |
| 1860 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1861 [CLSCompliant(false)] | |
| 1862 public static SByte ToSByte(Int64 p) { return checked((SByte)p); } | |
| 1863 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1864 [CLSCompliant(false)] | |
| 1865 public static SByte ToSByte(Single p) { return checked((SByte)p); } | |
| 1866 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1867 [CLSCompliant(false)] | |
| 1868 public static SByte ToSByte(String p) { return p == null? Configuration.NullableValues.SByte : SByte.Parse(p); } | |
| 1869 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1870 [CLSCompliant(false)] | |
| 1871 public static SByte ToSByte(UInt16 p) { return checked((SByte)p); } | |
| 1872 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1873 [CLSCompliant(false)] | |
| 1874 public static SByte ToSByte(UInt32 p) { return checked((SByte)p); } | |
| 1875 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1876 [CLSCompliant(false)] | |
| 1877 public static SByte ToSByte(UInt64 p) { return checked((SByte)p); } | |
| 1878 | |
| 1879 // Nullable Types | |
| 1880 // | |
| 1881 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1882 [CLSCompliant(false)] | |
| 1883 public static SByte ToSByte(Boolean? p) { return p.HasValue && p.Value ? (SByte)1: (SByte)0; } | |
| 1884 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1885 [CLSCompliant(false)] | |
| 1886 public static SByte ToSByte(Byte? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1887 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1888 [CLSCompliant(false)] | |
| 1889 public static SByte ToSByte(Char? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1890 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1891 [CLSCompliant(false)] | |
| 1892 public static SByte ToSByte(Decimal? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1893 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1894 [CLSCompliant(false)] | |
| 1895 public static SByte ToSByte(Double? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1896 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1897 [CLSCompliant(false)] | |
| 1898 public static SByte ToSByte(Int16? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1899 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1900 [CLSCompliant(false)] | |
| 1901 public static SByte ToSByte(Int32? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1902 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1903 [CLSCompliant(false)] | |
| 1904 public static SByte ToSByte(Int64? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1905 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1906 [CLSCompliant(false)] | |
| 1907 public static SByte ToSByte(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.SByte; } | |
| 1908 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1909 [CLSCompliant(false)] | |
| 1910 public static SByte ToSByte(Single? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1911 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1912 [CLSCompliant(false)] | |
| 1913 public static SByte ToSByte(UInt16? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1914 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1915 [CLSCompliant(false)] | |
| 1916 public static SByte ToSByte(UInt32? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1917 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1918 [CLSCompliant(false)] | |
| 1919 public static SByte ToSByte(UInt64? p) { return p.HasValue ? checked((SByte)p.Value) : Configuration.NullableValues.SByte; } | |
| 1920 | |
| 1921 // Other Types | |
| 1922 // | |
| 1923 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1924 [CLSCompliant(false)] | |
| 1925 public static SByte ToSByte(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.SByte : checked((SByte)p.ToArray()[0]); } | |
| 1926 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1927 [CLSCompliant(false)] | |
| 1928 public static SByte ToSByte(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.SByte : checked((SByte)p[0]); } | |
| 1929 | |
| 1930 #if !SILVERLIGHT | |
| 1931 | |
| 1932 // Sql Types | |
| 1933 // | |
| 1934 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1935 [CLSCompliant(false)] | |
| 1936 public static SByte ToSByte(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1937 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1938 [CLSCompliant(false)] | |
| 1939 public static SByte ToSByte(SqlByte p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1940 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1941 [CLSCompliant(false)] | |
| 1942 public static SByte ToSByte(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1943 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1944 [CLSCompliant(false)] | |
| 1945 public static SByte ToSByte(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1946 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1947 [CLSCompliant(false)] | |
| 1948 public static SByte ToSByte(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1949 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1950 [CLSCompliant(false)] | |
| 1951 public static SByte ToSByte(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1952 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1953 [CLSCompliant(false)] | |
| 1954 public static SByte ToSByte(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1955 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1956 [CLSCompliant(false)] | |
| 1957 public static SByte ToSByte(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1958 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1959 [CLSCompliant(false)] | |
| 1960 public static SByte ToSByte(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1961 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1962 [CLSCompliant(false)] | |
| 1963 public static SByte ToSByte(SqlString p) { return p.IsNull ? Configuration.NullableValues.SByte : ToSByte(p.Value); } | |
| 1964 | |
| 1965 #endif | |
| 1966 | |
| 1967 // From Object | |
| 1968 // | |
| 1969 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SByte</c> value.</summary> | |
| 1970 [CLSCompliant(false)] | |
| 1971 public static SByte ToSByte(object p) | |
| 1972 { | |
| 1973 if (p == null) return Configuration.NullableValues.SByte; | |
| 1974 | |
| 1975 var type = p.GetType(); | |
| 1976 | |
| 1977 // Primitive types | |
| 1978 // | |
| 1979 switch (Type.GetTypeCode(type)) | |
| 1980 { | |
| 1981 case TypeCode.DBNull : return Configuration.NullableValues.SByte; | |
| 1982 case TypeCode.SByte : return (SByte)p; | |
| 1983 case TypeCode.Int16 : return ToSByte((Int16) p); | |
| 1984 case TypeCode.Int32 : return ToSByte((Int32) p); | |
| 1985 case TypeCode.Int64 : return ToSByte((Int64) p); | |
| 1986 case TypeCode.Byte : return ToSByte((Byte) p); | |
| 1987 case TypeCode.UInt16 : return ToSByte((UInt16) p); | |
| 1988 case TypeCode.UInt32 : return ToSByte((UInt32) p); | |
| 1989 case TypeCode.UInt64 : return ToSByte((UInt64) p); | |
| 1990 case TypeCode.Single : return ToSByte((Single) p); | |
| 1991 case TypeCode.Double : return ToSByte((Double) p); | |
| 1992 case TypeCode.Decimal : return ToSByte((Decimal)p); | |
| 1993 case TypeCode.Char : return ToSByte((Char) p); | |
| 1994 case TypeCode.String : return ToSByte((String) p); | |
| 1995 case TypeCode.Boolean : return ToSByte((Boolean)p); | |
| 1996 } | |
| 1997 | |
| 1998 // Nullable Types | |
| 1999 // | |
| 2000 if (type.IsGenericType) | |
| 2001 { | |
| 2002 if (p is Boolean?) return ToSByte((Boolean?) p); | |
| 2003 if (p is Byte?) return ToSByte((Byte?) p); | |
| 2004 if (p is Char?) return ToSByte((Char?) p); | |
| 2005 if (p is Decimal?) return ToSByte((Decimal?) p); | |
| 2006 if (p is Double?) return ToSByte((Double?) p); | |
| 2007 if (p is Int16?) return ToSByte((Int16?) p); | |
| 2008 if (p is Int32?) return ToSByte((Int32?) p); | |
| 2009 if (p is Int64?) return ToSByte((Int64?) p); | |
| 2010 if (p is SByte?) return ToSByte((SByte?) p); | |
| 2011 if (p is Single?) return ToSByte((Single?) p); | |
| 2012 if (p is UInt16?) return ToSByte((UInt16?) p); | |
| 2013 if (p is UInt32?) return ToSByte((UInt32?) p); | |
| 2014 if (p is UInt64?) return ToSByte((UInt64?) p); | |
| 2015 } | |
| 2016 | |
| 2017 // Other Types | |
| 2018 // | |
| 2019 if (p is Binary) return ToSByte((Binary) p); | |
| 2020 if (p is Byte[]) return ToSByte((Byte[]) p); | |
| 2021 | |
| 2022 #if !SILVERLIGHT | |
| 2023 | |
| 2024 // Sql Types | |
| 2025 // | |
| 2026 if (p is INullable) | |
| 2027 { | |
| 2028 if (p is SqlBoolean) return ToSByte((SqlBoolean)p); | |
| 2029 if (p is SqlByte) return ToSByte((SqlByte) p); | |
| 2030 if (p is SqlDecimal) return ToSByte((SqlDecimal)p); | |
| 2031 if (p is SqlDouble) return ToSByte((SqlDouble) p); | |
| 2032 if (p is SqlInt16) return ToSByte((SqlInt16) p); | |
| 2033 if (p is SqlInt32) return ToSByte((SqlInt32) p); | |
| 2034 if (p is SqlInt64) return ToSByte((SqlInt64) p); | |
| 2035 if (p is SqlMoney) return ToSByte((SqlMoney) p); | |
| 2036 if (p is SqlSingle) return ToSByte((SqlSingle) p); | |
| 2037 if (p is SqlString) return ToSByte((SqlString) p); | |
| 2038 } | |
| 2039 | |
| 2040 #endif | |
| 2041 | |
| 2042 if (p is IConvertible) return ((IConvertible)p).ToSByte(null); | |
| 2043 | |
| 2044 throw CreateInvalidCastException(p.GetType(), typeof(SByte)); | |
| 2045 } | |
| 2046 | |
| 2047 #endregion | |
| 2048 | |
| 2049 #region Single | |
| 2050 | |
| 2051 // Simple Types | |
| 2052 // | |
| 2053 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Single</c> value.</summary> | |
| 2054 public static Single ToSingle(Boolean p) { return p ? (Single)1 : (Single)0; } | |
| 2055 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Single</c> value.</summary> | |
| 2056 public static Single ToSingle(Byte p) { return p; } | |
| 2057 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Single</c> value.</summary> | |
| 2058 public static Single ToSingle(Char p) { return p; } | |
| 2059 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Single</c> value.</summary> | |
| 2060 public static Single ToSingle(Decimal p) { return checked((Single)p); } | |
| 2061 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Single</c> value.</summary> | |
| 2062 public static Single ToSingle(Double p) { return checked((Single)p); } | |
| 2063 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Single</c> value.</summary> | |
| 2064 public static Single ToSingle(Int16 p) { return p; } | |
| 2065 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Single</c> value.</summary> | |
| 2066 public static Single ToSingle(Int32 p) { return p; } | |
| 2067 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Single</c> value.</summary> | |
| 2068 public static Single ToSingle(Int64 p) { return p; } | |
| 2069 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Single</c> value.</summary> | |
| 2070 [CLSCompliant(false)] | |
| 2071 public static Single ToSingle(SByte p) { return p; } | |
| 2072 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Single</c> value.</summary> | |
| 2073 public static Single ToSingle(String p) { return p == null? Configuration.NullableValues.Single : Single.Parse(p); } | |
| 2074 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Single</c> value.</summary> | |
| 2075 [CLSCompliant(false)] | |
| 2076 public static Single ToSingle(UInt16 p) { return p; } | |
| 2077 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Single</c> value.</summary> | |
| 2078 [CLSCompliant(false)] | |
| 2079 public static Single ToSingle(UInt32 p) { return p; } | |
| 2080 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Single</c> value.</summary> | |
| 2081 [CLSCompliant(false)] | |
| 2082 public static Single ToSingle(UInt64 p) { return p; } | |
| 2083 | |
| 2084 // Nullable Types | |
| 2085 // | |
| 2086 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2087 public static Single ToSingle(Boolean? p) { return p.HasValue && p.Value ? (Single)1: (Single)0; } | |
| 2088 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2089 public static Single ToSingle(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2090 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2091 public static Single ToSingle(Char? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2092 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2093 public static Single ToSingle(Decimal? p) { return p.HasValue ? checked((Single)p.Value) : Configuration.NullableValues.Single; } | |
| 2094 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2095 public static Single ToSingle(Double? p) { return p.HasValue ? checked((Single)p.Value) : Configuration.NullableValues.Single; } | |
| 2096 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2097 public static Single ToSingle(Int16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2098 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2099 public static Single ToSingle(Int32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2100 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2101 public static Single ToSingle(Int64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2102 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2103 [CLSCompliant(false)] | |
| 2104 public static Single ToSingle(SByte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2105 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2106 public static Single ToSingle(Single? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2107 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2108 [CLSCompliant(false)] | |
| 2109 public static Single ToSingle(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2110 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2111 [CLSCompliant(false)] | |
| 2112 public static Single ToSingle(UInt32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2113 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Single</c> value.</summary> | |
| 2114 [CLSCompliant(false)] | |
| 2115 public static Single ToSingle(UInt64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.Single; } | |
| 2116 | |
| 2117 // Other Types | |
| 2118 // | |
| 2119 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Single</c> value.</summary> | |
| 2120 public static Single ToSingle(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Single : BitConverter.ToSingle(p.ToArray(), 0); } | |
| 2121 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Single</c> value.</summary> | |
| 2122 public static Single ToSingle(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.Single : BitConverter.ToSingle(p, 0); } | |
| 2123 | |
| 2124 #if !SILVERLIGHT | |
| 2125 | |
| 2126 // Sql Types | |
| 2127 // | |
| 2128 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Single</c> value.</summary> | |
| 2129 public static Single ToSingle(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.Single : ToSingle(p.Value); } | |
| 2130 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Single</c> value.</summary> | |
| 2131 public static Single ToSingle(SqlByte p) { return p.IsNull ? Configuration.NullableValues.Single : p.Value; } | |
| 2132 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Single</c> value.</summary> | |
| 2133 public static Single ToSingle(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.Single : ToSingle(p.Value); } | |
| 2134 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Single</c> value.</summary> | |
| 2135 public static Single ToSingle(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.Single : ToSingle(p.Value); } | |
| 2136 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Single</c> value.</summary> | |
| 2137 public static Single ToSingle(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.Single : p.Value; } | |
| 2138 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Single</c> value.</summary> | |
| 2139 public static Single ToSingle(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.Single : p.Value; } | |
| 2140 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Single</c> value.</summary> | |
| 2141 public static Single ToSingle(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.Single : p.Value; } | |
| 2142 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Single</c> value.</summary> | |
| 2143 public static Single ToSingle(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.Single : ToSingle(p.Value); } | |
| 2144 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Single</c> value.</summary> | |
| 2145 public static Single ToSingle(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.Single : p.Value; } | |
| 2146 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Single</c> value.</summary> | |
| 2147 public static Single ToSingle(SqlString p) { return p.IsNull ? Configuration.NullableValues.Single : ToSingle(p.Value); } | |
| 2148 | |
| 2149 #endif | |
| 2150 | |
| 2151 // From Object | |
| 2152 // | |
| 2153 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Single</c> value.</summary> | |
| 2154 public static Single ToSingle(object p) | |
| 2155 { | |
| 2156 if (p == null) return Configuration.NullableValues.Single; | |
| 2157 | |
| 2158 var type = p.GetType(); | |
| 2159 | |
| 2160 // Primitive types | |
| 2161 // | |
| 2162 switch (Type.GetTypeCode(type)) | |
| 2163 { | |
| 2164 case TypeCode.DBNull : return Configuration.NullableValues.Single; | |
| 2165 case TypeCode.Single : return (Single)p; | |
| 2166 case TypeCode.SByte : return ToSingle((SByte) p); | |
| 2167 case TypeCode.Int16 : return ToSingle((Int16) p); | |
| 2168 case TypeCode.Int32 : return ToSingle((Int32) p); | |
| 2169 case TypeCode.Int64 : return ToSingle((Int64) p); | |
| 2170 case TypeCode.Byte : return ToSingle((Byte) p); | |
| 2171 case TypeCode.UInt16 : return ToSingle((UInt16) p); | |
| 2172 case TypeCode.UInt32 : return ToSingle((UInt32) p); | |
| 2173 case TypeCode.Char : return ToSingle((Char) p); | |
| 2174 case TypeCode.UInt64 : return ToSingle((UInt64) p); | |
| 2175 case TypeCode.Double : return ToSingle((Double) p); | |
| 2176 case TypeCode.Decimal : return ToSingle((Decimal)p); | |
| 2177 case TypeCode.String : return ToSingle((String) p); | |
| 2178 case TypeCode.Boolean : return ToSingle((Boolean)p); | |
| 2179 } | |
| 2180 | |
| 2181 // Nullable Types | |
| 2182 // | |
| 2183 if (type.IsGenericType) | |
| 2184 { | |
| 2185 if (p is Boolean?) return ToSingle((Boolean?) p); | |
| 2186 if (p is Byte?) return ToSingle((Byte?) p); | |
| 2187 if (p is Char?) return ToSingle((Char?) p); | |
| 2188 if (p is Decimal?) return ToSingle((Decimal?) p); | |
| 2189 if (p is Double?) return ToSingle((Double?) p); | |
| 2190 if (p is Int16?) return ToSingle((Int16?) p); | |
| 2191 if (p is Int32?) return ToSingle((Int32?) p); | |
| 2192 if (p is Int64?) return ToSingle((Int64?) p); | |
| 2193 if (p is SByte?) return ToSingle((SByte?) p); | |
| 2194 if (p is Single?) return ToSingle((Single?) p); | |
| 2195 if (p is UInt16?) return ToSingle((UInt16?) p); | |
| 2196 if (p is UInt32?) return ToSingle((UInt32?) p); | |
| 2197 if (p is UInt64?) return ToSingle((UInt64?) p); | |
| 2198 } | |
| 2199 | |
| 2200 // Other Types | |
| 2201 // | |
| 2202 if (p is Binary) return ToSingle((Binary) p); | |
| 2203 if (p is Byte[]) return ToSingle((Byte[]) p); | |
| 2204 | |
| 2205 #if !SILVERLIGHT | |
| 2206 | |
| 2207 // Sql Types | |
| 2208 // | |
| 2209 if (p is INullable) | |
| 2210 { | |
| 2211 if (p is SqlBoolean) return ToSingle((SqlBoolean)p); | |
| 2212 if (p is SqlByte) return ToSingle((SqlByte) p); | |
| 2213 if (p is SqlDecimal) return ToSingle((SqlDecimal)p); | |
| 2214 if (p is SqlDouble) return ToSingle((SqlDouble) p); | |
| 2215 if (p is SqlInt16) return ToSingle((SqlInt16) p); | |
| 2216 if (p is SqlInt32) return ToSingle((SqlInt32) p); | |
| 2217 if (p is SqlInt64) return ToSingle((SqlInt64) p); | |
| 2218 if (p is SqlMoney) return ToSingle((SqlMoney) p); | |
| 2219 if (p is SqlSingle) return ToSingle((SqlSingle) p); | |
| 2220 if (p is SqlString) return ToSingle((SqlString) p); | |
| 2221 } | |
| 2222 | |
| 2223 #endif | |
| 2224 | |
| 2225 if (p is IConvertible) return ((IConvertible)p).ToSingle(null); | |
| 2226 | |
| 2227 throw CreateInvalidCastException(p.GetType(), typeof(Single)); | |
| 2228 } | |
| 2229 | |
| 2230 #endregion | |
| 2231 | |
| 2232 #region String | |
| 2233 | |
| 2234 // Simple Types | |
| 2235 // | |
| 2236 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>String</c> value.</summary> | |
| 2237 public static String ToString(Boolean p) { return p.ToString(); } | |
| 2238 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>String</c> value.</summary> | |
| 2239 public static String ToString(Byte p) { return p.ToString(); } | |
| 2240 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>String</c> value.</summary> | |
| 2241 public static String ToString(Char p) { return p.ToString(); } | |
| 2242 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>String</c> value.</summary> | |
| 2243 public static String ToString(DateTime p) { return p.ToString(); } | |
| 2244 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>String</c> value.</summary> | |
| 2245 public static String ToString(DateTimeOffset p) { return p.ToString(); } | |
| 2246 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>String</c> value.</summary> | |
| 2247 public static String ToString(Decimal p) { return p.ToString(); } | |
| 2248 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>String</c> value.</summary> | |
| 2249 public static String ToString(Double p) { return p.ToString(); } | |
| 2250 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>String</c> value.</summary> | |
| 2251 public static String ToString(Guid p) { return p.ToString(); } | |
| 2252 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>String</c> value.</summary> | |
| 2253 public static String ToString(Int16 p) { return p.ToString(); } | |
| 2254 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>String</c> value.</summary> | |
| 2255 public static String ToString(Int32 p) { return p.ToString(); } | |
| 2256 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>String</c> value.</summary> | |
| 2257 public static String ToString(Int64 p) { return p.ToString(); } | |
| 2258 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>String</c> value.</summary> | |
| 2259 [CLSCompliant(false)] | |
| 2260 public static String ToString(SByte p) { return p.ToString(); } | |
| 2261 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>String</c> value.</summary> | |
| 2262 public static String ToString(Single p) { return p.ToString(); } | |
| 2263 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>String</c> value.</summary> | |
| 2264 public static String ToString(TimeSpan p) { return p.ToString(); } | |
| 2265 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>String</c> value.</summary> | |
| 2266 [CLSCompliant(false)] | |
| 2267 public static String ToString(UInt16 p) { return p.ToString(); } | |
| 2268 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>String</c> value.</summary> | |
| 2269 [CLSCompliant(false)] | |
| 2270 public static String ToString(UInt32 p) { return p.ToString(); } | |
| 2271 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>String</c> value.</summary> | |
| 2272 [CLSCompliant(false)] | |
| 2273 public static String ToString(UInt64 p) { return p.ToString(); } | |
| 2274 | |
| 2275 // Nullable Types | |
| 2276 // | |
| 2277 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>String</c> value.</summary> | |
| 2278 public static String ToString(Boolean? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2279 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>String</c> value.</summary> | |
| 2280 public static String ToString(Byte? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2281 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>String</c> value.</summary> | |
| 2282 public static String ToString(Char? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2283 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>String</c> value.</summary> | |
| 2284 public static String ToString(DateTime? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2285 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>String</c> value.</summary> | |
| 2286 public static String ToString(DateTimeOffset? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2287 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>String</c> value.</summary> | |
| 2288 public static String ToString(Decimal? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2289 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>String</c> value.</summary> | |
| 2290 public static String ToString(Double? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2291 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>String</c> value.</summary> | |
| 2292 public static String ToString(Guid? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2293 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>String</c> value.</summary> | |
| 2294 public static String ToString(Int16? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2295 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>String</c> value.</summary> | |
| 2296 public static String ToString(Int32? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2297 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>String</c> value.</summary> | |
| 2298 public static String ToString(Int64? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2299 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>String</c> value.</summary> | |
| 2300 [CLSCompliant(false)] | |
| 2301 public static String ToString(SByte? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2302 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>String</c> value.</summary> | |
| 2303 public static String ToString(Single? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2304 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>String</c> value.</summary> | |
| 2305 public static String ToString(TimeSpan? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2306 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>String</c> value.</summary> | |
| 2307 [CLSCompliant(false)] | |
| 2308 public static String ToString(UInt16? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2309 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>String</c> value.</summary> | |
| 2310 [CLSCompliant(false)] | |
| 2311 public static String ToString(UInt32? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2312 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>String</c> value.</summary> | |
| 2313 [CLSCompliant(false)] | |
| 2314 public static String ToString(UInt64? p) { return p.HasValue ? p.Value.ToString() : Configuration.NullableValues.String; } | |
| 2315 | |
| 2316 // Other Types | |
| 2317 // | |
| 2318 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>String</c> value.</summary> | |
| 2319 public static String ToString(Binary p) { return ToString(p.ToArray()); } | |
| 2320 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>String</c> value.</summary> | |
| 2321 public static String ToString(Byte[] p) { return p == null ? Configuration.NullableValues.String : System.Text.Encoding.UTF8.GetString(p, 0, p.Length); } | |
| 2322 /// <summary>Converts the value from <c>Type</c> to an equivalent <c>String</c> value.</summary> | |
| 2323 public static String ToString(Type p) { return p == null ? Configuration.NullableValues.String : p.FullName; } | |
| 2324 | |
| 2325 #if !SILVERLIGHT | |
| 2326 | |
| 2327 // Sql Types | |
| 2328 // | |
| 2329 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>String</c> value.</summary> | |
| 2330 public static String ToString(SqlBoolean p) { return p.ToString(); } | |
| 2331 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>String</c> value.</summary> | |
| 2332 public static String ToString(SqlByte p) { return p.ToString(); } | |
| 2333 /// <summary>Converts the value from <c>SqlChars</c> to an equivalent <c>String</c> value.</summary> | |
| 2334 public static String ToString(SqlChars p) { return p.IsNull ? Configuration.NullableValues.String : p.ToSqlString().Value; } | |
| 2335 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>String</c> value.</summary> | |
| 2336 public static String ToString(SqlDecimal p) { return p.ToString(); } | |
| 2337 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>String</c> value.</summary> | |
| 2338 public static String ToString(SqlDouble p) { return p.ToString(); } | |
| 2339 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>String</c> value.</summary> | |
| 2340 public static String ToString(SqlGuid p) { return p.ToString(); } | |
| 2341 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>String</c> value.</summary> | |
| 2342 public static String ToString(SqlInt16 p) { return p.ToString(); } | |
| 2343 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>String</c> value.</summary> | |
| 2344 public static String ToString(SqlInt32 p) { return p.ToString(); } | |
| 2345 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>String</c> value.</summary> | |
| 2346 public static String ToString(SqlInt64 p) { return p.ToString(); } | |
| 2347 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>String</c> value.</summary> | |
| 2348 public static String ToString(SqlMoney p) { return p.ToString(); } | |
| 2349 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>String</c> value.</summary> | |
| 2350 public static String ToString(SqlSingle p) { return p.ToString(); } | |
| 2351 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>String</c> value.</summary> | |
| 2352 public static String ToString(SqlString p) { return p.ToString(); } | |
| 2353 /// <summary>Converts the value from <c>SqlXml</c> to an equivalent <c>String</c> value.</summary> | |
| 2354 public static String ToString(SqlXml p) { return p.IsNull ? Configuration.NullableValues.String : p.Value; } | |
| 2355 | |
| 2356 // Other Types | |
| 2357 // | |
| 2358 /// <summary>Converts the value from <c>XElement</c> to an equivalent <c>String</c> value.</summary> | |
| 2359 public static String ToString(XElement p) { return p == null ? Configuration.NullableValues.String : p.ToString(); } | |
| 2360 /// <summary>Converts the value from <c>XmlDocument</c> to an equivalent <c>String</c> value.</summary> | |
| 2361 public static String ToString(XmlDocument p) { return p == null ? Configuration.NullableValues.String : p.InnerXml; } | |
| 2362 | |
| 2363 #endif | |
| 2364 | |
| 2365 // From Object | |
| 2366 // | |
| 2367 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>String</c> value.</summary> | |
| 2368 public static String ToString(object p) | |
| 2369 { | |
| 2370 if (p == null) return Configuration.NullableValues.String; | |
| 2371 | |
| 2372 var type = p.GetType(); | |
| 2373 | |
| 2374 // Primitive types | |
| 2375 // | |
| 2376 switch (Type.GetTypeCode(type)) | |
| 2377 { | |
| 2378 case TypeCode.DBNull : return Configuration.NullableValues.String; | |
| 2379 case TypeCode.String : return (String)p; | |
| 2380 case TypeCode.SByte : return ToString((SByte) p); | |
| 2381 case TypeCode.Int16 : return ToString((Int16) p); | |
| 2382 case TypeCode.Int32 : return ToString((Int32) p); | |
| 2383 case TypeCode.Int64 : return ToString((Int64) p); | |
| 2384 case TypeCode.Byte : return ToString((Byte) p); | |
| 2385 case TypeCode.UInt16 : return ToString((UInt16) p); | |
| 2386 case TypeCode.UInt32 : return ToString((UInt32) p); | |
| 2387 case TypeCode.UInt64 : return ToString((UInt64) p); | |
| 2388 case TypeCode.Single : return ToString((Single) p); | |
| 2389 case TypeCode.Double : return ToString((Double) p); | |
| 2390 case TypeCode.Boolean : return ToString((Boolean) p); | |
| 2391 case TypeCode.Decimal : return ToString((Decimal) p); | |
| 2392 case TypeCode.Char : return ToString((Char) p); | |
| 2393 case TypeCode.DateTime : return ToString((DateTime)p); | |
| 2394 } | |
| 2395 | |
| 2396 // Simple Types | |
| 2397 // | |
| 2398 if (p is DateTimeOffset) return ToString((DateTimeOffset) p); | |
| 2399 if (p is Guid) return ToString((Guid) p); | |
| 2400 if (p is TimeSpan) return ToString((TimeSpan) p); | |
| 2401 | |
| 2402 // Nullable Types | |
| 2403 // | |
| 2404 if (type.IsGenericType) | |
| 2405 { | |
| 2406 if (p is Boolean?) return ToString((Boolean?) p); | |
| 2407 if (p is Byte?) return ToString((Byte?) p); | |
| 2408 if (p is Char?) return ToString((Char?) p); | |
| 2409 if (p is DateTime?) return ToString((DateTime?) p); | |
| 2410 if (p is DateTimeOffset?) return ToString((DateTimeOffset?)p); | |
| 2411 if (p is Decimal?) return ToString((Decimal?) p); | |
| 2412 if (p is Double?) return ToString((Double?) p); | |
| 2413 if (p is Guid?) return ToString((Guid?) p); | |
| 2414 if (p is Int16?) return ToString((Int16?) p); | |
| 2415 if (p is Int32?) return ToString((Int32?) p); | |
| 2416 if (p is Int64?) return ToString((Int64?) p); | |
| 2417 if (p is SByte?) return ToString((SByte?) p); | |
| 2418 if (p is Single?) return ToString((Single?) p); | |
| 2419 if (p is TimeSpan?) return ToString((TimeSpan?) p); | |
| 2420 if (p is UInt16?) return ToString((UInt16?) p); | |
| 2421 if (p is UInt32?) return ToString((UInt32?) p); | |
| 2422 if (p is UInt64?) return ToString((UInt64?) p); | |
| 2423 } | |
| 2424 | |
| 2425 // Other Types | |
| 2426 // | |
| 2427 if (p is Binary) return ToString((Binary) p); | |
| 2428 if (p is Byte[]) return ToString((Byte[]) p); | |
| 2429 if (p is Type) return ToString((Type) p); | |
| 2430 | |
| 2431 #if !SILVERLIGHT | |
| 2432 | |
| 2433 // Sql Types | |
| 2434 // | |
| 2435 if (p is INullable) | |
| 2436 { | |
| 2437 if (p is SqlBoolean) return ToString((SqlBoolean) p); | |
| 2438 if (p is SqlByte) return ToString((SqlByte) p); | |
| 2439 if (p is SqlChars) return ToString((SqlChars) p); | |
| 2440 if (p is SqlDecimal) return ToString((SqlDecimal) p); | |
| 2441 if (p is SqlDouble) return ToString((SqlDouble) p); | |
| 2442 if (p is SqlGuid) return ToString((SqlGuid) p); | |
| 2443 if (p is SqlInt16) return ToString((SqlInt16) p); | |
| 2444 if (p is SqlInt32) return ToString((SqlInt32) p); | |
| 2445 if (p is SqlInt64) return ToString((SqlInt64) p); | |
| 2446 if (p is SqlMoney) return ToString((SqlMoney) p); | |
| 2447 if (p is SqlSingle) return ToString((SqlSingle) p); | |
| 2448 if (p is SqlString) return ToString((SqlString) p); | |
| 2449 if (p is SqlXml) return ToString((SqlXml) p); | |
| 2450 } | |
| 2451 | |
| 2452 // Other Types | |
| 2453 // | |
| 2454 if (p is XElement) return ToString((XElement) p); | |
| 2455 if (p is XmlDocument) return ToString((XmlDocument) p); | |
| 2456 | |
| 2457 #endif | |
| 2458 | |
| 2459 if (p is IConvertible) return ((IConvertible)p).ToString(null); | |
| 2460 | |
| 2461 return p.ToString(); | |
| 2462 } | |
| 2463 | |
| 2464 #endregion | |
| 2465 | |
| 2466 #region TimeSpan | |
| 2467 | |
| 2468 // Simple Types | |
| 2469 // | |
| 2470 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2471 public static TimeSpan ToTimeSpan(DateTime p) { return p - DateTime.MinValue; } | |
| 2472 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2473 public static TimeSpan ToTimeSpan(DateTimeOffset p) { return p - DateTimeOffset.MinValue; } | |
| 2474 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2475 public static TimeSpan ToTimeSpan(Double p) { return TimeSpan.FromDays (p); } | |
| 2476 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2477 public static TimeSpan ToTimeSpan(Int64 p) { return TimeSpan.FromTicks(p); } | |
| 2478 /// <summary>Converts the value from <c>String</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2479 public static TimeSpan ToTimeSpan(String p) { return p == null? Configuration.NullableValues.TimeSpan : TimeSpan.Parse(p); } | |
| 2480 | |
| 2481 // Nullable Types | |
| 2482 // | |
| 2483 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2484 public static TimeSpan ToTimeSpan(DateTime? p) { return p.HasValue ? p.Value - DateTime.MinValue : Configuration.NullableValues.TimeSpan; } | |
| 2485 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2486 public static TimeSpan ToTimeSpan(DateTimeOffset? p) { return p.HasValue ? p.Value - DateTimeOffset.MinValue : Configuration.NullableValues.TimeSpan; } | |
| 2487 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2488 public static TimeSpan ToTimeSpan(Double? p) { return p.HasValue ? TimeSpan.FromDays (p.Value) : Configuration.NullableValues.TimeSpan; } | |
| 2489 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2490 public static TimeSpan ToTimeSpan(Int64? p) { return p.HasValue ? TimeSpan.FromTicks(p.Value) : Configuration.NullableValues.TimeSpan; } | |
| 2491 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2492 public static TimeSpan ToTimeSpan(TimeSpan? p) { return p.HasValue ? p.Value : Configuration.NullableValues.TimeSpan; } | |
| 2493 | |
| 2494 // Other Types | |
| 2495 // | |
| 2496 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2497 public static TimeSpan ToTimeSpan(Binary p) { return p == null || p.Length == 0? Configuration.NullableValues.TimeSpan : TimeSpan.FromTicks(ToInt64(p.ToArray())); } | |
| 2498 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2499 public static TimeSpan ToTimeSpan(Byte[] p) { return p == null || p.Length == 0? Configuration.NullableValues.TimeSpan : TimeSpan.FromTicks(ToInt64(p)); } | |
| 2500 | |
| 2501 #if !SILVERLIGHT | |
| 2502 | |
| 2503 // Sql Types | |
| 2504 // | |
| 2505 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2506 public static TimeSpan ToTimeSpan(SqlDateTime p) { return p.IsNull ? Configuration.NullableValues.TimeSpan : p.Value - DateTime.MinValue; } | |
| 2507 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2508 public static TimeSpan ToTimeSpan(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.TimeSpan : TimeSpan.FromDays(p.Value); } | |
| 2509 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2510 public static TimeSpan ToTimeSpan(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.TimeSpan : TimeSpan.FromTicks(p.Value); } | |
| 2511 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2512 public static TimeSpan ToTimeSpan(SqlString p) { return p.IsNull ? Configuration.NullableValues.TimeSpan : TimeSpan.Parse(p.Value); } | |
| 2513 | |
| 2514 #endif | |
| 2515 | |
| 2516 // From Object | |
| 2517 // | |
| 2518 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>TimeSpan</c> value.</summary> | |
| 2519 public static TimeSpan ToTimeSpan(object p) | |
| 2520 { | |
| 2521 if (p == null) return Configuration.NullableValues.TimeSpan; | |
| 2522 | |
| 2523 if (p is TimeSpan) return (TimeSpan)p; | |
| 2524 | |
| 2525 var type = p.GetType(); | |
| 2526 | |
| 2527 // Primitive types | |
| 2528 // | |
| 2529 switch (Type.GetTypeCode(type)) | |
| 2530 { | |
| 2531 case TypeCode.DBNull : return Configuration.NullableValues.TimeSpan; | |
| 2532 case TypeCode.DateTime : return ToTimeSpan((DateTime)p); | |
| 2533 case TypeCode.Int64 : return ToTimeSpan((Int64) p); | |
| 2534 case TypeCode.Double : return ToTimeSpan((Double) p); | |
| 2535 case TypeCode.String : return ToTimeSpan((String) p); | |
| 2536 } | |
| 2537 | |
| 2538 // Simple Types | |
| 2539 // | |
| 2540 if (p is DateTimeOffset) return ToTimeSpan((DateTimeOffset) p); | |
| 2541 | |
| 2542 // Nullable Types | |
| 2543 // | |
| 2544 if (type.IsGenericType) | |
| 2545 { | |
| 2546 if (p is DateTime?) return ToTimeSpan((DateTime?) p); | |
| 2547 if (p is DateTimeOffset?) return ToTimeSpan((DateTimeOffset?)p); | |
| 2548 if (p is Double?) return ToTimeSpan((Double?) p); | |
| 2549 if (p is Int64?) return ToTimeSpan((Int64?) p); | |
| 2550 if (p is TimeSpan?) return ToTimeSpan((TimeSpan?) p); | |
| 2551 } | |
| 2552 | |
| 2553 // Other Types | |
| 2554 // | |
| 2555 if (p is Binary) return ToTimeSpan((Binary) p); | |
| 2556 if (p is Byte[]) return ToTimeSpan((Byte[]) p); | |
| 2557 | |
| 2558 #if !SILVERLIGHT | |
| 2559 | |
| 2560 // Sql Types | |
| 2561 // | |
| 2562 if (p is INullable) | |
| 2563 { | |
| 2564 if (p is SqlDateTime) return ToTimeSpan((SqlDateTime) p); | |
| 2565 if (p is SqlDouble) return ToTimeSpan((SqlDouble) p); | |
| 2566 if (p is SqlInt64) return ToTimeSpan((SqlInt64) p); | |
| 2567 if (p is SqlString) return ToTimeSpan((SqlString) p); | |
| 2568 } | |
| 2569 | |
| 2570 #endif | |
| 2571 | |
| 2572 throw CreateInvalidCastException(p.GetType(), typeof(TimeSpan)); | |
| 2573 } | |
| 2574 | |
| 2575 #endregion | |
| 2576 | |
| 2577 #region UInt16 | |
| 2578 | |
| 2579 // Simple Types | |
| 2580 // | |
| 2581 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2582 [CLSCompliant(false)] | |
| 2583 public static UInt16 ToUInt16(Boolean p) { return p ? (UInt16)1 : (UInt16)0; } | |
| 2584 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2585 [CLSCompliant(false)] | |
| 2586 public static UInt16 ToUInt16(Byte p) { return p; } | |
| 2587 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2588 [CLSCompliant(false)] | |
| 2589 public static UInt16 ToUInt16(Char p) { return checked((UInt16)p); } | |
| 2590 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2591 [CLSCompliant(false)] | |
| 2592 public static UInt16 ToUInt16(Decimal p) { return checked((UInt16)p); } | |
| 2593 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2594 [CLSCompliant(false)] | |
| 2595 public static UInt16 ToUInt16(Double p) { return checked((UInt16)p); } | |
| 2596 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2597 [CLSCompliant(false)] | |
| 2598 public static UInt16 ToUInt16(Int16 p) { return checked((UInt16)p); } | |
| 2599 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2600 [CLSCompliant(false)] | |
| 2601 public static UInt16 ToUInt16(Int32 p) { return checked((UInt16)p); } | |
| 2602 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2603 [CLSCompliant(false)] | |
| 2604 public static UInt16 ToUInt16(Int64 p) { return checked((UInt16)p); } | |
| 2605 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2606 [CLSCompliant(false)] | |
| 2607 public static UInt16 ToUInt16(SByte p) { return checked((UInt16)p); } | |
| 2608 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2609 [CLSCompliant(false)] | |
| 2610 public static UInt16 ToUInt16(Single p) { return checked((UInt16)p); } | |
| 2611 /// <summary>Converts the value from <c>String</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2612 [CLSCompliant(false)] | |
| 2613 public static UInt16 ToUInt16(String p) { return p == null? Configuration.NullableValues.UInt16 : UInt16.Parse(p); } | |
| 2614 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2615 [CLSCompliant(false)] | |
| 2616 public static UInt16 ToUInt16(UInt32 p) { return checked((UInt16)p); } | |
| 2617 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2618 [CLSCompliant(false)] | |
| 2619 public static UInt16 ToUInt16(UInt64 p) { return checked((UInt16)p); } | |
| 2620 | |
| 2621 // Nullable Types | |
| 2622 // | |
| 2623 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2624 [CLSCompliant(false)] | |
| 2625 public static UInt16 ToUInt16(Boolean? p) { return p.HasValue && p.Value ? (UInt16)1: (UInt16)0; } | |
| 2626 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2627 [CLSCompliant(false)] | |
| 2628 public static UInt16 ToUInt16(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt16; } | |
| 2629 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2630 [CLSCompliant(false)] | |
| 2631 public static UInt16 ToUInt16(Char? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2632 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2633 [CLSCompliant(false)] | |
| 2634 public static UInt16 ToUInt16(Decimal? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2635 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2636 [CLSCompliant(false)] | |
| 2637 public static UInt16 ToUInt16(Double? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2638 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2639 [CLSCompliant(false)] | |
| 2640 public static UInt16 ToUInt16(Int16? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2641 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2642 [CLSCompliant(false)] | |
| 2643 public static UInt16 ToUInt16(Int32? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2644 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2645 [CLSCompliant(false)] | |
| 2646 public static UInt16 ToUInt16(Int64? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2647 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2648 [CLSCompliant(false)] | |
| 2649 public static UInt16 ToUInt16(SByte? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2650 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2651 [CLSCompliant(false)] | |
| 2652 public static UInt16 ToUInt16(Single? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2653 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2654 [CLSCompliant(false)] | |
| 2655 public static UInt16 ToUInt16(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt16; } | |
| 2656 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2657 [CLSCompliant(false)] | |
| 2658 public static UInt16 ToUInt16(UInt32? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2659 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2660 [CLSCompliant(false)] | |
| 2661 public static UInt16 ToUInt16(UInt64? p) { return p.HasValue ? checked((UInt16)p.Value) : Configuration.NullableValues.UInt16; } | |
| 2662 | |
| 2663 // Other Types | |
| 2664 // | |
| 2665 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2666 [CLSCompliant(false)] | |
| 2667 public static UInt16 ToUInt16(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.UInt16 : BitConverter.ToUInt16(p.ToArray(), 0); } | |
| 2668 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2669 [CLSCompliant(false)] | |
| 2670 public static UInt16 ToUInt16(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.UInt16 : BitConverter.ToUInt16(p, 0); } | |
| 2671 | |
| 2672 #if !SILVERLIGHT | |
| 2673 | |
| 2674 // Sql Types | |
| 2675 // | |
| 2676 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2677 [CLSCompliant(false)] | |
| 2678 public static UInt16 ToUInt16(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2679 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2680 [CLSCompliant(false)] | |
| 2681 public static UInt16 ToUInt16(SqlByte p) { return p.IsNull ? Configuration.NullableValues.UInt16 : p.Value; } | |
| 2682 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2683 [CLSCompliant(false)] | |
| 2684 public static UInt16 ToUInt16(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2685 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2686 [CLSCompliant(false)] | |
| 2687 public static UInt16 ToUInt16(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2688 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2689 [CLSCompliant(false)] | |
| 2690 public static UInt16 ToUInt16(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2691 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2692 [CLSCompliant(false)] | |
| 2693 public static UInt16 ToUInt16(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2694 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2695 [CLSCompliant(false)] | |
| 2696 public static UInt16 ToUInt16(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2697 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2698 [CLSCompliant(false)] | |
| 2699 public static UInt16 ToUInt16(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2700 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2701 [CLSCompliant(false)] | |
| 2702 public static UInt16 ToUInt16(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2703 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2704 [CLSCompliant(false)] | |
| 2705 public static UInt16 ToUInt16(SqlString p) { return p.IsNull ? Configuration.NullableValues.UInt16 : ToUInt16(p.Value); } | |
| 2706 | |
| 2707 #endif | |
| 2708 | |
| 2709 // From Object | |
| 2710 // | |
| 2711 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>UInt16</c> value.</summary> | |
| 2712 [CLSCompliant(false)] | |
| 2713 public static UInt16 ToUInt16(object p) | |
| 2714 { | |
| 2715 if (p == null) return Configuration.NullableValues.UInt16; | |
| 2716 | |
| 2717 var type = p.GetType(); | |
| 2718 | |
| 2719 // Primitive types | |
| 2720 // | |
| 2721 switch (Type.GetTypeCode(type)) | |
| 2722 { | |
| 2723 case TypeCode.DBNull : return Configuration.NullableValues.UInt16; | |
| 2724 case TypeCode.UInt16 : return (UInt16)p; | |
| 2725 case TypeCode.Byte : return ToUInt16((Byte) p); | |
| 2726 case TypeCode.SByte : return ToUInt16((SByte) p); | |
| 2727 case TypeCode.Int16 : return ToUInt16((Int16) p); | |
| 2728 case TypeCode.Int32 : return ToUInt16((Int32) p); | |
| 2729 case TypeCode.Int64 : return ToUInt16((Int64) p); | |
| 2730 case TypeCode.UInt32 : return ToUInt16((UInt32) p); | |
| 2731 case TypeCode.UInt64 : return ToUInt16((UInt64) p); | |
| 2732 case TypeCode.Single : return ToUInt16((Single) p); | |
| 2733 case TypeCode.Double : return ToUInt16((Double) p); | |
| 2734 case TypeCode.Decimal : return ToUInt16((Decimal)p); | |
| 2735 case TypeCode.Char : return ToUInt16((Char) p); | |
| 2736 case TypeCode.String : return ToUInt16((String) p); | |
| 2737 case TypeCode.Boolean : return ToUInt16((Boolean)p); | |
| 2738 } | |
| 2739 | |
| 2740 // Nullable Types | |
| 2741 // | |
| 2742 if (type.IsGenericType) | |
| 2743 { | |
| 2744 if (p is Boolean?) return ToUInt16((Boolean?) p); | |
| 2745 if (p is Byte?) return ToUInt16((Byte?) p); | |
| 2746 if (p is Char?) return ToUInt16((Char?) p); | |
| 2747 if (p is Decimal?) return ToUInt16((Decimal?) p); | |
| 2748 if (p is Double?) return ToUInt16((Double?) p); | |
| 2749 if (p is Int16?) return ToUInt16((Int16?) p); | |
| 2750 if (p is Int32?) return ToUInt16((Int32?) p); | |
| 2751 if (p is Int64?) return ToUInt16((Int64?) p); | |
| 2752 if (p is SByte?) return ToUInt16((SByte?) p); | |
| 2753 if (p is Single?) return ToUInt16((Single?) p); | |
| 2754 if (p is UInt16?) return ToUInt16((UInt16?) p); | |
| 2755 if (p is UInt32?) return ToUInt16((UInt32?) p); | |
| 2756 if (p is UInt64?) return ToUInt16((UInt64?) p); | |
| 2757 } | |
| 2758 | |
| 2759 // Other Types | |
| 2760 // | |
| 2761 if (p is Binary) return ToUInt16((Binary) p); | |
| 2762 if (p is Byte[]) return ToUInt16((Byte[]) p); | |
| 2763 | |
| 2764 #if !SILVERLIGHT | |
| 2765 | |
| 2766 // Sql Types | |
| 2767 // | |
| 2768 if (p is INullable) | |
| 2769 { | |
| 2770 if (p is SqlBoolean) return ToUInt16((SqlBoolean)p); | |
| 2771 if (p is SqlByte) return ToUInt16((SqlByte) p); | |
| 2772 if (p is SqlDecimal) return ToUInt16((SqlDecimal)p); | |
| 2773 if (p is SqlDouble) return ToUInt16((SqlDouble) p); | |
| 2774 if (p is SqlInt16) return ToUInt16((SqlInt16) p); | |
| 2775 if (p is SqlInt32) return ToUInt16((SqlInt32) p); | |
| 2776 if (p is SqlInt64) return ToUInt16((SqlInt64) p); | |
| 2777 if (p is SqlMoney) return ToUInt16((SqlMoney) p); | |
| 2778 if (p is SqlSingle) return ToUInt16((SqlSingle) p); | |
| 2779 if (p is SqlString) return ToUInt16((SqlString) p); | |
| 2780 } | |
| 2781 | |
| 2782 #endif | |
| 2783 | |
| 2784 if (p is IConvertible) return ((IConvertible)p).ToUInt16(null); | |
| 2785 | |
| 2786 throw CreateInvalidCastException(p.GetType(), typeof(UInt16)); | |
| 2787 } | |
| 2788 | |
| 2789 #endregion | |
| 2790 | |
| 2791 #region UInt32 | |
| 2792 | |
| 2793 // Simple Types | |
| 2794 // | |
| 2795 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2796 [CLSCompliant(false)] | |
| 2797 public static UInt32 ToUInt32(Boolean p) { return p ? (UInt32)1 : (UInt32)0; } | |
| 2798 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2799 [CLSCompliant(false)] | |
| 2800 public static UInt32 ToUInt32(Byte p) { return p; } | |
| 2801 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2802 [CLSCompliant(false)] | |
| 2803 public static UInt32 ToUInt32(Char p) { return checked((UInt32)p); } | |
| 2804 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2805 [CLSCompliant(false)] | |
| 2806 public static UInt32 ToUInt32(Decimal p) { return checked((UInt32)p); } | |
| 2807 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2808 [CLSCompliant(false)] | |
| 2809 public static UInt32 ToUInt32(Double p) { return checked((UInt32)p); } | |
| 2810 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2811 [CLSCompliant(false)] | |
| 2812 public static UInt32 ToUInt32(Int16 p) { return checked((UInt32)p); } | |
| 2813 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2814 [CLSCompliant(false)] | |
| 2815 public static UInt32 ToUInt32(Int32 p) { return checked((UInt32)p); } | |
| 2816 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2817 [CLSCompliant(false)] | |
| 2818 public static UInt32 ToUInt32(Int64 p) { return checked((UInt32)p); } | |
| 2819 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2820 [CLSCompliant(false)] | |
| 2821 public static UInt32 ToUInt32(SByte p) { return checked((UInt32)p); } | |
| 2822 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2823 [CLSCompliant(false)] | |
| 2824 public static UInt32 ToUInt32(Single p) { return checked((UInt32)p); } | |
| 2825 /// <summary>Converts the value from <c>String</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2826 [CLSCompliant(false)] | |
| 2827 public static UInt32 ToUInt32(String p) { return p == null? Configuration.NullableValues.UInt32 : UInt32.Parse(p); } | |
| 2828 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2829 [CLSCompliant(false)] | |
| 2830 public static UInt32 ToUInt32(UInt16 p) { return p; } | |
| 2831 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2832 [CLSCompliant(false)] | |
| 2833 public static UInt32 ToUInt32(UInt64 p) { return checked((UInt32)p); } | |
| 2834 | |
| 2835 // Nullable Types | |
| 2836 // | |
| 2837 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2838 [CLSCompliant(false)] | |
| 2839 public static UInt32 ToUInt32(Boolean? p) { return p.HasValue && p.Value ? (UInt32)1: (UInt32)0; } | |
| 2840 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2841 [CLSCompliant(false)] | |
| 2842 public static UInt32 ToUInt32(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt32; } | |
| 2843 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2844 [CLSCompliant(false)] | |
| 2845 public static UInt32 ToUInt32(Char? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2846 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2847 [CLSCompliant(false)] | |
| 2848 public static UInt32 ToUInt32(Decimal? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2849 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2850 [CLSCompliant(false)] | |
| 2851 public static UInt32 ToUInt32(Double? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2852 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2853 [CLSCompliant(false)] | |
| 2854 public static UInt32 ToUInt32(Int16? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2855 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2856 [CLSCompliant(false)] | |
| 2857 public static UInt32 ToUInt32(Int32? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2858 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2859 [CLSCompliant(false)] | |
| 2860 public static UInt32 ToUInt32(Int64? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2861 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2862 [CLSCompliant(false)] | |
| 2863 public static UInt32 ToUInt32(SByte? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2864 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2865 [CLSCompliant(false)] | |
| 2866 public static UInt32 ToUInt32(Single? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2867 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2868 [CLSCompliant(false)] | |
| 2869 public static UInt32 ToUInt32(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt32; } | |
| 2870 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2871 [CLSCompliant(false)] | |
| 2872 public static UInt32 ToUInt32(UInt32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt32; } | |
| 2873 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2874 [CLSCompliant(false)] | |
| 2875 public static UInt32 ToUInt32(UInt64? p) { return p.HasValue ? checked((UInt32)p.Value) : Configuration.NullableValues.UInt32; } | |
| 2876 | |
| 2877 // Other Types | |
| 2878 // | |
| 2879 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2880 [CLSCompliant(false)] | |
| 2881 public static UInt32 ToUInt32(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.UInt32 : BitConverter.ToUInt32(p.ToArray(), 0); } | |
| 2882 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2883 [CLSCompliant(false)] | |
| 2884 public static UInt32 ToUInt32(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.UInt32 : BitConverter.ToUInt32(p, 0); } | |
| 2885 | |
| 2886 #if !SILVERLIGHT | |
| 2887 | |
| 2888 // Sql Types | |
| 2889 // | |
| 2890 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2891 [CLSCompliant(false)] | |
| 2892 public static UInt32 ToUInt32(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2893 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2894 [CLSCompliant(false)] | |
| 2895 public static UInt32 ToUInt32(SqlByte p) { return p.IsNull ? Configuration.NullableValues.UInt32 : p.Value; } | |
| 2896 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2897 [CLSCompliant(false)] | |
| 2898 public static UInt32 ToUInt32(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2899 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2900 [CLSCompliant(false)] | |
| 2901 public static UInt32 ToUInt32(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2902 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2903 [CLSCompliant(false)] | |
| 2904 public static UInt32 ToUInt32(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2905 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2906 [CLSCompliant(false)] | |
| 2907 public static UInt32 ToUInt32(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2908 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2909 [CLSCompliant(false)] | |
| 2910 public static UInt32 ToUInt32(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2911 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2912 [CLSCompliant(false)] | |
| 2913 public static UInt32 ToUInt32(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2914 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2915 [CLSCompliant(false)] | |
| 2916 public static UInt32 ToUInt32(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2917 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2918 [CLSCompliant(false)] | |
| 2919 public static UInt32 ToUInt32(SqlString p) { return p.IsNull ? Configuration.NullableValues.UInt32 : ToUInt32(p.Value); } | |
| 2920 | |
| 2921 #endif | |
| 2922 | |
| 2923 // From Object | |
| 2924 // | |
| 2925 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>UInt32</c> value.</summary> | |
| 2926 [CLSCompliant(false)] | |
| 2927 public static UInt32 ToUInt32(object p) | |
| 2928 { | |
| 2929 if (p == null) return Configuration.NullableValues.UInt32; | |
| 2930 | |
| 2931 var type = p.GetType(); | |
| 2932 | |
| 2933 // Primitive types | |
| 2934 // | |
| 2935 switch (Type.GetTypeCode(type)) | |
| 2936 { | |
| 2937 case TypeCode.DBNull : return Configuration.NullableValues.UInt32; | |
| 2938 case TypeCode.UInt32 : return (UInt32)p; | |
| 2939 case TypeCode.Byte : return ToUInt32((Byte) p); | |
| 2940 case TypeCode.UInt16 : return ToUInt32((UInt16) p); | |
| 2941 case TypeCode.SByte : return ToUInt32((SByte) p); | |
| 2942 case TypeCode.Int16 : return ToUInt32((Int16) p); | |
| 2943 case TypeCode.Int32 : return ToUInt32((Int32) p); | |
| 2944 case TypeCode.Int64 : return ToUInt32((Int64) p); | |
| 2945 case TypeCode.UInt64 : return ToUInt32((UInt64) p); | |
| 2946 case TypeCode.Single : return ToUInt32((Single) p); | |
| 2947 case TypeCode.Double : return ToUInt32((Double) p); | |
| 2948 case TypeCode.Decimal : return ToUInt32((Decimal)p); | |
| 2949 case TypeCode.Char : return ToUInt32((Char) p); | |
| 2950 case TypeCode.String : return ToUInt32((String) p); | |
| 2951 case TypeCode.Boolean : return ToUInt32((Boolean)p); | |
| 2952 } | |
| 2953 | |
| 2954 // Nullable Types | |
| 2955 // | |
| 2956 if (type.IsGenericType) | |
| 2957 { | |
| 2958 if (p is Boolean?) return ToUInt32((Boolean?) p); | |
| 2959 if (p is Byte?) return ToUInt32((Byte?) p); | |
| 2960 if (p is Char?) return ToUInt32((Char?) p); | |
| 2961 if (p is Decimal?) return ToUInt32((Decimal?) p); | |
| 2962 if (p is Double?) return ToUInt32((Double?) p); | |
| 2963 if (p is Int16?) return ToUInt32((Int16?) p); | |
| 2964 if (p is Int32?) return ToUInt32((Int32?) p); | |
| 2965 if (p is Int64?) return ToUInt32((Int64?) p); | |
| 2966 if (p is SByte?) return ToUInt32((SByte?) p); | |
| 2967 if (p is Single?) return ToUInt32((Single?) p); | |
| 2968 if (p is UInt16?) return ToUInt32((UInt16?) p); | |
| 2969 if (p is UInt32?) return ToUInt32((UInt32?) p); | |
| 2970 if (p is UInt64?) return ToUInt32((UInt64?) p); | |
| 2971 } | |
| 2972 | |
| 2973 // Other Types | |
| 2974 // | |
| 2975 if (p is Binary) return ToUInt32((Binary) p); | |
| 2976 if (p is Byte[]) return ToUInt32((Byte[]) p); | |
| 2977 | |
| 2978 #if !SILVERLIGHT | |
| 2979 | |
| 2980 // Sql Types | |
| 2981 // | |
| 2982 if (p is INullable) | |
| 2983 { | |
| 2984 if (p is SqlBoolean) return ToUInt32((SqlBoolean)p); | |
| 2985 if (p is SqlByte) return ToUInt32((SqlByte) p); | |
| 2986 if (p is SqlDecimal) return ToUInt32((SqlDecimal)p); | |
| 2987 if (p is SqlDouble) return ToUInt32((SqlDouble) p); | |
| 2988 if (p is SqlInt16) return ToUInt32((SqlInt16) p); | |
| 2989 if (p is SqlInt32) return ToUInt32((SqlInt32) p); | |
| 2990 if (p is SqlInt64) return ToUInt32((SqlInt64) p); | |
| 2991 if (p is SqlMoney) return ToUInt32((SqlMoney) p); | |
| 2992 if (p is SqlSingle) return ToUInt32((SqlSingle) p); | |
| 2993 if (p is SqlString) return ToUInt32((SqlString) p); | |
| 2994 } | |
| 2995 | |
| 2996 #endif | |
| 2997 | |
| 2998 if (p is IConvertible) return ((IConvertible)p).ToUInt32(null); | |
| 2999 | |
| 3000 throw CreateInvalidCastException(p.GetType(), typeof(UInt32)); | |
| 3001 } | |
| 3002 | |
| 3003 #endregion | |
| 3004 | |
| 3005 #region UInt64 | |
| 3006 | |
| 3007 // Simple Types | |
| 3008 // | |
| 3009 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3010 [CLSCompliant(false)] | |
| 3011 public static UInt64 ToUInt64(Boolean p) { return p ? (UInt64)1 : (UInt64)0; } | |
| 3012 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3013 [CLSCompliant(false)] | |
| 3014 public static UInt64 ToUInt64(Byte p) { return p; } | |
| 3015 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3016 [CLSCompliant(false)] | |
| 3017 public static UInt64 ToUInt64(Char p) { return checked((UInt64)p); } | |
| 3018 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3019 [CLSCompliant(false)] | |
| 3020 public static UInt64 ToUInt64(Decimal p) { return checked((UInt64)p); } | |
| 3021 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3022 [CLSCompliant(false)] | |
| 3023 public static UInt64 ToUInt64(Double p) { return checked((UInt64)p); } | |
| 3024 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3025 [CLSCompliant(false)] | |
| 3026 public static UInt64 ToUInt64(Int16 p) { return checked((UInt64)p); } | |
| 3027 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3028 [CLSCompliant(false)] | |
| 3029 public static UInt64 ToUInt64(Int32 p) { return checked((UInt64)p); } | |
| 3030 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3031 [CLSCompliant(false)] | |
| 3032 public static UInt64 ToUInt64(Int64 p) { return checked((UInt64)p); } | |
| 3033 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3034 [CLSCompliant(false)] | |
| 3035 public static UInt64 ToUInt64(SByte p) { return checked((UInt64)p); } | |
| 3036 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3037 [CLSCompliant(false)] | |
| 3038 public static UInt64 ToUInt64(Single p) { return checked((UInt64)p); } | |
| 3039 /// <summary>Converts the value from <c>String</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3040 [CLSCompliant(false)] | |
| 3041 public static UInt64 ToUInt64(String p) { return p == null? Configuration.NullableValues.UInt64 : UInt64.Parse(p); } | |
| 3042 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3043 [CLSCompliant(false)] | |
| 3044 public static UInt64 ToUInt64(UInt16 p) { return p; } | |
| 3045 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3046 [CLSCompliant(false)] | |
| 3047 public static UInt64 ToUInt64(UInt32 p) { return p; } | |
| 3048 | |
| 3049 // Nullable Types | |
| 3050 // | |
| 3051 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3052 [CLSCompliant(false)] | |
| 3053 public static UInt64 ToUInt64(Boolean? p) { return p.HasValue && p.Value ? (UInt64)1: (UInt64)0; } | |
| 3054 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3055 [CLSCompliant(false)] | |
| 3056 public static UInt64 ToUInt64(Byte? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt64; } | |
| 3057 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3058 [CLSCompliant(false)] | |
| 3059 public static UInt64 ToUInt64(Char? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3060 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3061 [CLSCompliant(false)] | |
| 3062 public static UInt64 ToUInt64(Decimal? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3063 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3064 [CLSCompliant(false)] | |
| 3065 public static UInt64 ToUInt64(Double? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3066 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3067 [CLSCompliant(false)] | |
| 3068 public static UInt64 ToUInt64(Int16? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3069 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3070 [CLSCompliant(false)] | |
| 3071 public static UInt64 ToUInt64(Int32? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3072 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3073 [CLSCompliant(false)] | |
| 3074 public static UInt64 ToUInt64(Int64? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3075 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3076 [CLSCompliant(false)] | |
| 3077 public static UInt64 ToUInt64(SByte? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3078 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3079 [CLSCompliant(false)] | |
| 3080 public static UInt64 ToUInt64(Single? p) { return p.HasValue ? checked((UInt64)p.Value) : Configuration.NullableValues.UInt64; } | |
| 3081 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3082 [CLSCompliant(false)] | |
| 3083 public static UInt64 ToUInt64(UInt16? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt64; } | |
| 3084 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3085 [CLSCompliant(false)] | |
| 3086 public static UInt64 ToUInt64(UInt32? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt64; } | |
| 3087 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3088 [CLSCompliant(false)] | |
| 3089 public static UInt64 ToUInt64(UInt64? p) { return p.HasValue ? p.Value : Configuration.NullableValues.UInt64; } | |
| 3090 | |
| 3091 // Other Types | |
| 3092 // | |
| 3093 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3094 [CLSCompliant(false)] | |
| 3095 public static UInt64 ToUInt64(Binary p) { return p == null || p.Length == 0 ? Configuration.NullableValues.UInt64 : BitConverter.ToUInt64(p.ToArray(), 0); } | |
| 3096 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3097 [CLSCompliant(false)] | |
| 3098 public static UInt64 ToUInt64(Byte[] p) { return p == null || p.Length == 0 ? Configuration.NullableValues.UInt64 : BitConverter.ToUInt64(p, 0); } | |
| 3099 | |
| 3100 #if !SILVERLIGHT | |
| 3101 | |
| 3102 // Sql Types | |
| 3103 // | |
| 3104 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3105 [CLSCompliant(false)] | |
| 3106 public static UInt64 ToUInt64(SqlBoolean p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3107 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3108 [CLSCompliant(false)] | |
| 3109 public static UInt64 ToUInt64(SqlByte p) { return p.IsNull ? Configuration.NullableValues.UInt64 : p.Value; } | |
| 3110 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3111 [CLSCompliant(false)] | |
| 3112 public static UInt64 ToUInt64(SqlDecimal p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3113 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3114 [CLSCompliant(false)] | |
| 3115 public static UInt64 ToUInt64(SqlDouble p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3116 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3117 [CLSCompliant(false)] | |
| 3118 public static UInt64 ToUInt64(SqlInt16 p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3119 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3120 [CLSCompliant(false)] | |
| 3121 public static UInt64 ToUInt64(SqlInt32 p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3122 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3123 [CLSCompliant(false)] | |
| 3124 public static UInt64 ToUInt64(SqlInt64 p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3125 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3126 [CLSCompliant(false)] | |
| 3127 public static UInt64 ToUInt64(SqlMoney p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3128 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3129 [CLSCompliant(false)] | |
| 3130 public static UInt64 ToUInt64(SqlSingle p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3131 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3132 [CLSCompliant(false)] | |
| 3133 public static UInt64 ToUInt64(SqlString p) { return p.IsNull ? Configuration.NullableValues.UInt64 : ToUInt64(p.Value); } | |
| 3134 | |
| 3135 #endif | |
| 3136 | |
| 3137 // From Object | |
| 3138 // | |
| 3139 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>UInt64</c> value.</summary> | |
| 3140 [CLSCompliant(false)] | |
| 3141 public static UInt64 ToUInt64(object p) | |
| 3142 { | |
| 3143 if (p == null) return Configuration.NullableValues.UInt64; | |
| 3144 | |
| 3145 var type = p.GetType(); | |
| 3146 | |
| 3147 // Primitive types | |
| 3148 // | |
| 3149 switch (Type.GetTypeCode(type)) | |
| 3150 { | |
| 3151 case TypeCode.DBNull : return Configuration.NullableValues.UInt64; | |
| 3152 case TypeCode.UInt64 : return (UInt64)p; | |
| 3153 case TypeCode.Byte : return ToUInt64((Byte) p); | |
| 3154 case TypeCode.UInt16 : return ToUInt64((UInt16) p); | |
| 3155 case TypeCode.UInt32 : return ToUInt64((UInt32) p); | |
| 3156 case TypeCode.SByte : return ToUInt64((SByte) p); | |
| 3157 case TypeCode.Int16 : return ToUInt64((Int16) p); | |
| 3158 case TypeCode.Int32 : return ToUInt64((Int32) p); | |
| 3159 case TypeCode.Int64 : return ToUInt64((Int64) p); | |
| 3160 case TypeCode.Single : return ToUInt64((Single) p); | |
| 3161 case TypeCode.Double : return ToUInt64((Double) p); | |
| 3162 case TypeCode.Decimal : return ToUInt64((Decimal)p); | |
| 3163 case TypeCode.Char : return ToUInt64((Char) p); | |
| 3164 case TypeCode.String : return ToUInt64((String) p); | |
| 3165 case TypeCode.Boolean : return ToUInt64((Boolean)p); | |
| 3166 } | |
| 3167 | |
| 3168 // Nullable Types | |
| 3169 // | |
| 3170 if (type.IsGenericType) | |
| 3171 { | |
| 3172 if (p is Boolean?) return ToUInt64((Boolean?) p); | |
| 3173 if (p is Byte?) return ToUInt64((Byte?) p); | |
| 3174 if (p is Char?) return ToUInt64((Char?) p); | |
| 3175 if (p is Decimal?) return ToUInt64((Decimal?) p); | |
| 3176 if (p is Double?) return ToUInt64((Double?) p); | |
| 3177 if (p is Int16?) return ToUInt64((Int16?) p); | |
| 3178 if (p is Int32?) return ToUInt64((Int32?) p); | |
| 3179 if (p is Int64?) return ToUInt64((Int64?) p); | |
| 3180 if (p is SByte?) return ToUInt64((SByte?) p); | |
| 3181 if (p is Single?) return ToUInt64((Single?) p); | |
| 3182 if (p is UInt16?) return ToUInt64((UInt16?) p); | |
| 3183 if (p is UInt32?) return ToUInt64((UInt32?) p); | |
| 3184 if (p is UInt64?) return ToUInt64((UInt64?) p); | |
| 3185 } | |
| 3186 | |
| 3187 // Other Types | |
| 3188 // | |
| 3189 if (p is Binary) return ToUInt64((Binary) p); | |
| 3190 if (p is Byte[]) return ToUInt64((Byte[]) p); | |
| 3191 | |
| 3192 #if !SILVERLIGHT | |
| 3193 | |
| 3194 // Sql Types | |
| 3195 // | |
| 3196 if (p is INullable) | |
| 3197 { | |
| 3198 if (p is SqlBoolean) return ToUInt64((SqlBoolean)p); | |
| 3199 if (p is SqlByte) return ToUInt64((SqlByte) p); | |
| 3200 if (p is SqlDecimal) return ToUInt64((SqlDecimal)p); | |
| 3201 if (p is SqlDouble) return ToUInt64((SqlDouble) p); | |
| 3202 if (p is SqlInt16) return ToUInt64((SqlInt16) p); | |
| 3203 if (p is SqlInt32) return ToUInt64((SqlInt32) p); | |
| 3204 if (p is SqlInt64) return ToUInt64((SqlInt64) p); | |
| 3205 if (p is SqlMoney) return ToUInt64((SqlMoney) p); | |
| 3206 if (p is SqlSingle) return ToUInt64((SqlSingle) p); | |
| 3207 if (p is SqlString) return ToUInt64((SqlString) p); | |
| 3208 } | |
| 3209 | |
| 3210 #endif | |
| 3211 | |
| 3212 if (p is IConvertible) return ((IConvertible)p).ToUInt64(null); | |
| 3213 | |
| 3214 throw CreateInvalidCastException(p.GetType(), typeof(UInt64)); | |
| 3215 } | |
| 3216 | |
| 3217 #endregion | |
| 3218 | |
| 3219 #endregion | |
| 3220 | |
| 3221 #region Nullable Types | |
| 3222 | |
| 3223 #region Boolean? | |
| 3224 | |
| 3225 // Simple Types | |
| 3226 // | |
| 3227 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3228 public static Boolean? ToNullableBoolean(Boolean p) { return p; } | |
| 3229 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3230 public static Boolean? ToNullableBoolean(Byte p) { return p != 0; } | |
| 3231 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3232 public static Boolean? ToNullableBoolean(Char p) { return ToBoolean(p); } | |
| 3233 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3234 public static Boolean? ToNullableBoolean(Decimal p) { return p != 0; } | |
| 3235 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3236 public static Boolean? ToNullableBoolean(Double p) { return p != 0; } | |
| 3237 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3238 public static Boolean? ToNullableBoolean(Int16 p) { return p != 0; } | |
| 3239 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3240 public static Boolean? ToNullableBoolean(Int32 p) { return p != 0; } | |
| 3241 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3242 public static Boolean? ToNullableBoolean(Int64 p) { return p != 0; } | |
| 3243 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3244 [CLSCompliant(false)] | |
| 3245 public static Boolean? ToNullableBoolean(SByte p) { return p != 0; } | |
| 3246 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3247 public static Boolean? ToNullableBoolean(Single p) { return p != 0; } | |
| 3248 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3249 public static Boolean? ToNullableBoolean(String p) { return p == null? (Boolean?)null : p.Length == 1 ? ToBoolean(p[0]) : Boolean.Parse(p); } | |
| 3250 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3251 [CLSCompliant(false)] | |
| 3252 public static Boolean? ToNullableBoolean(UInt16 p) { return p != 0; } | |
| 3253 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3254 [CLSCompliant(false)] | |
| 3255 public static Boolean? ToNullableBoolean(UInt32 p) { return p != 0; } | |
| 3256 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3257 [CLSCompliant(false)] | |
| 3258 public static Boolean? ToNullableBoolean(UInt64 p) { return p != 0; } | |
| 3259 | |
| 3260 // Nullable Types | |
| 3261 // | |
| 3262 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3263 public static Boolean? ToNullableBoolean(Byte? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3264 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3265 public static Boolean? ToNullableBoolean(Char? p) { return p.HasValue && ToBoolean(p.Value); } | |
| 3266 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3267 public static Boolean? ToNullableBoolean(Decimal? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3268 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3269 public static Boolean? ToNullableBoolean(Double? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3270 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3271 public static Boolean? ToNullableBoolean(Int16? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3272 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3273 public static Boolean? ToNullableBoolean(Int32? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3274 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3275 public static Boolean? ToNullableBoolean(Int64? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3276 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3277 [CLSCompliant(false)] | |
| 3278 public static Boolean? ToNullableBoolean(SByte? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3279 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3280 public static Boolean? ToNullableBoolean(Single? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3281 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3282 [CLSCompliant(false)] | |
| 3283 public static Boolean? ToNullableBoolean(UInt16? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3284 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3285 [CLSCompliant(false)] | |
| 3286 public static Boolean? ToNullableBoolean(UInt32? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3287 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3288 [CLSCompliant(false)] | |
| 3289 public static Boolean? ToNullableBoolean(UInt64? p) { return p.HasValue ? p.Value != 0 : (Boolean?)null; } | |
| 3290 | |
| 3291 // Other Types | |
| 3292 // | |
| 3293 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3294 public static Boolean? ToNullableBoolean(Binary p) { return p == null || p.Length == 0 ? (Boolean?)null : BitConverter.ToBoolean(p.ToArray(), 0); } | |
| 3295 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3296 public static Boolean? ToNullableBoolean(Byte[] p) { return p == null || p.Length == 0 ? (Boolean?)null : BitConverter.ToBoolean(p, 0); } | |
| 3297 | |
| 3298 #if !SILVERLIGHT | |
| 3299 | |
| 3300 // Sql Types | |
| 3301 // | |
| 3302 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3303 public static Boolean? ToNullableBoolean(SqlBoolean p) { return p.IsNull ? (Boolean?)null : p.Value; } | |
| 3304 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3305 public static Boolean? ToNullableBoolean(SqlByte p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3306 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3307 public static Boolean? ToNullableBoolean(SqlDecimal p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3308 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3309 public static Boolean? ToNullableBoolean(SqlDouble p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3310 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3311 public static Boolean? ToNullableBoolean(SqlInt16 p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3312 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3313 public static Boolean? ToNullableBoolean(SqlInt32 p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3314 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3315 public static Boolean? ToNullableBoolean(SqlInt64 p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3316 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3317 public static Boolean? ToNullableBoolean(SqlMoney p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3318 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3319 public static Boolean? ToNullableBoolean(SqlSingle p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3320 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3321 public static Boolean? ToNullableBoolean(SqlString p) { return p.IsNull ? (Boolean?)null : ToBoolean(p.Value); } | |
| 3322 | |
| 3323 #endif | |
| 3324 | |
| 3325 // From Object | |
| 3326 // | |
| 3327 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Boolean?</c> value.</summary> | |
| 3328 public static Boolean? ToNullableBoolean(object p) | |
| 3329 { | |
| 3330 if (p == null) return null; | |
| 3331 | |
| 3332 if (p is Boolean?) return (Boolean?)p; | |
| 3333 | |
| 3334 var type = p.GetType(); | |
| 3335 | |
| 3336 // Primitive types | |
| 3337 // | |
| 3338 switch (Type.GetTypeCode(type)) | |
| 3339 { | |
| 3340 case TypeCode.DBNull : return null; | |
| 3341 case TypeCode.String : return ToNullableBoolean((String) p); | |
| 3342 case TypeCode.Boolean : return ToNullableBoolean((Boolean) p); | |
| 3343 case TypeCode.Char : return ToNullableBoolean((Char) p); | |
| 3344 case TypeCode.SByte : return ToNullableBoolean((SByte) p); | |
| 3345 case TypeCode.Int16 : return ToNullableBoolean((Int16) p); | |
| 3346 case TypeCode.Int32 : return ToNullableBoolean((Int32) p); | |
| 3347 case TypeCode.Int64 : return ToNullableBoolean((Int64) p); | |
| 3348 case TypeCode.Byte : return ToNullableBoolean((Byte) p); | |
| 3349 case TypeCode.UInt16 : return ToNullableBoolean((UInt16) p); | |
| 3350 case TypeCode.UInt32 : return ToNullableBoolean((UInt32) p); | |
| 3351 case TypeCode.UInt64 : return ToNullableBoolean((UInt64) p); | |
| 3352 case TypeCode.Single : return ToNullableBoolean((Single) p); | |
| 3353 case TypeCode.Double : return ToNullableBoolean((Double) p); | |
| 3354 case TypeCode.Decimal : return ToNullableBoolean((Decimal) p); | |
| 3355 } | |
| 3356 | |
| 3357 // Nullable Types | |
| 3358 // | |
| 3359 if (type.IsGenericType) | |
| 3360 { | |
| 3361 if (p is Byte?) return ToNullableBoolean((Byte?) p); | |
| 3362 if (p is Char?) return ToNullableBoolean((Char?) p); | |
| 3363 if (p is Decimal?) return ToNullableBoolean((Decimal?) p); | |
| 3364 if (p is Double?) return ToNullableBoolean((Double?) p); | |
| 3365 if (p is Int16?) return ToNullableBoolean((Int16?) p); | |
| 3366 if (p is Int32?) return ToNullableBoolean((Int32?) p); | |
| 3367 if (p is Int64?) return ToNullableBoolean((Int64?) p); | |
| 3368 if (p is SByte?) return ToNullableBoolean((SByte?) p); | |
| 3369 if (p is Single?) return ToNullableBoolean((Single?) p); | |
| 3370 if (p is UInt16?) return ToNullableBoolean((UInt16?) p); | |
| 3371 if (p is UInt32?) return ToNullableBoolean((UInt32?) p); | |
| 3372 if (p is UInt64?) return ToNullableBoolean((UInt64?) p); | |
| 3373 } | |
| 3374 | |
| 3375 // Other Types | |
| 3376 // | |
| 3377 if (p is Binary) return ToNullableBoolean((Binary) p); | |
| 3378 if (p is Byte[]) return ToNullableBoolean((Byte[]) p); | |
| 3379 | |
| 3380 #if !SILVERLIGHT | |
| 3381 | |
| 3382 // Sql Types | |
| 3383 // | |
| 3384 if (p is INullable) | |
| 3385 { | |
| 3386 if (p is SqlBoolean) return ToNullableBoolean((SqlBoolean)p); | |
| 3387 if (p is SqlByte) return ToNullableBoolean((SqlByte) p); | |
| 3388 if (p is SqlDecimal) return ToNullableBoolean((SqlDecimal)p); | |
| 3389 if (p is SqlDouble) return ToNullableBoolean((SqlDouble) p); | |
| 3390 if (p is SqlInt16) return ToNullableBoolean((SqlInt16) p); | |
| 3391 if (p is SqlInt32) return ToNullableBoolean((SqlInt32) p); | |
| 3392 if (p is SqlInt64) return ToNullableBoolean((SqlInt64) p); | |
| 3393 if (p is SqlMoney) return ToNullableBoolean((SqlMoney) p); | |
| 3394 if (p is SqlSingle) return ToNullableBoolean((SqlSingle) p); | |
| 3395 if (p is SqlString) return ToNullableBoolean((SqlString) p); | |
| 3396 } | |
| 3397 | |
| 3398 #endif | |
| 3399 | |
| 3400 throw CreateInvalidCastException(p.GetType(), typeof(Boolean?)); | |
| 3401 } | |
| 3402 | |
| 3403 #endregion | |
| 3404 | |
| 3405 #region Byte? | |
| 3406 | |
| 3407 // Simple Types | |
| 3408 // | |
| 3409 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3410 public static Byte? ToNullableByte(Boolean p) { return p ? (Byte?)1 : (Byte?)0; } | |
| 3411 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3412 public static Byte? ToNullableByte(Byte p) { return p; } | |
| 3413 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3414 public static Byte? ToNullableByte(Char p) { return checked((Byte?)p); } | |
| 3415 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3416 public static Byte? ToNullableByte(Decimal p) { return checked((Byte?)p); } | |
| 3417 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3418 public static Byte? ToNullableByte(Double p) { return checked((Byte?)p); } | |
| 3419 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3420 public static Byte? ToNullableByte(Int16 p) { return checked((Byte?)p); } | |
| 3421 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3422 public static Byte? ToNullableByte(Int32 p) { return checked((Byte?)p); } | |
| 3423 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3424 public static Byte? ToNullableByte(Int64 p) { return checked((Byte?)p); } | |
| 3425 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3426 [CLSCompliant(false)] | |
| 3427 public static Byte? ToNullableByte(SByte p) { return checked((Byte?)p); } | |
| 3428 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3429 public static Byte? ToNullableByte(Single p) { return checked((Byte?)p); } | |
| 3430 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3431 public static Byte? ToNullableByte(String p) { return p == null? (Byte?)null : Byte.Parse(p); } | |
| 3432 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3433 [CLSCompliant(false)] | |
| 3434 public static Byte? ToNullableByte(UInt16 p) { return checked((Byte?)p); } | |
| 3435 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3436 [CLSCompliant(false)] | |
| 3437 public static Byte? ToNullableByte(UInt32 p) { return checked((Byte?)p); } | |
| 3438 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3439 [CLSCompliant(false)] | |
| 3440 public static Byte? ToNullableByte(UInt64 p) { return checked((Byte?)p); } | |
| 3441 | |
| 3442 // Nullable Types | |
| 3443 // | |
| 3444 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3445 public static Byte? ToNullableByte(Boolean? p) { return p.HasValue && p.Value ? (Byte?)1: (Byte?)0; } | |
| 3446 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3447 public static Byte? ToNullableByte(Char? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3448 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3449 public static Byte? ToNullableByte(Decimal? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3450 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3451 public static Byte? ToNullableByte(Double? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3452 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3453 public static Byte? ToNullableByte(Int16? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3454 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3455 public static Byte? ToNullableByte(Int32? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3456 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3457 public static Byte? ToNullableByte(Int64? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3458 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3459 [CLSCompliant(false)] | |
| 3460 public static Byte? ToNullableByte(SByte? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3461 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3462 public static Byte? ToNullableByte(Single? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3463 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3464 [CLSCompliant(false)] | |
| 3465 public static Byte? ToNullableByte(UInt16? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3466 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3467 [CLSCompliant(false)] | |
| 3468 public static Byte? ToNullableByte(UInt32? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3469 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3470 [CLSCompliant(false)] | |
| 3471 public static Byte? ToNullableByte(UInt64? p) { return p.HasValue ? checked((Byte?)p.Value) : (Byte?)null; } | |
| 3472 | |
| 3473 // Other Types | |
| 3474 // | |
| 3475 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3476 public static Byte? ToNullableByte(Binary p) { return p == null || p.Length == 0 ? (Byte?)null : p.ToArray()[0]; } | |
| 3477 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3478 public static Byte? ToNullableByte(Byte[] p) { return p == null || p.Length == 0 ? (Byte?)null : p[0]; } | |
| 3479 | |
| 3480 #if !SILVERLIGHT | |
| 3481 | |
| 3482 // Sql Types | |
| 3483 // | |
| 3484 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3485 public static Byte? ToNullableByte(SqlBoolean p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3486 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3487 public static Byte? ToNullableByte(SqlByte p) { return p.IsNull ? (Byte?)null : p.Value; } | |
| 3488 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3489 public static Byte? ToNullableByte(SqlDecimal p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3490 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3491 public static Byte? ToNullableByte(SqlDouble p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3492 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3493 public static Byte? ToNullableByte(SqlInt16 p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3494 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3495 public static Byte? ToNullableByte(SqlInt32 p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3496 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3497 public static Byte? ToNullableByte(SqlInt64 p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3498 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3499 public static Byte? ToNullableByte(SqlMoney p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3500 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3501 public static Byte? ToNullableByte(SqlSingle p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3502 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3503 public static Byte? ToNullableByte(SqlString p) { return p.IsNull ? (Byte?)null : ToByte(p.Value); } | |
| 3504 | |
| 3505 #endif | |
| 3506 | |
| 3507 // From Object | |
| 3508 // | |
| 3509 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Byte?</c> value.</summary> | |
| 3510 public static Byte? ToNullableByte(object p) | |
| 3511 { | |
| 3512 if (p == null) return null; | |
| 3513 | |
| 3514 if (p is Byte?) return (Byte?)p; | |
| 3515 | |
| 3516 var type = p.GetType(); | |
| 3517 | |
| 3518 // Primitive types | |
| 3519 // | |
| 3520 switch (Type.GetTypeCode(type)) | |
| 3521 { | |
| 3522 case TypeCode.DBNull : return null; | |
| 3523 case TypeCode.Byte : return ToNullableByte((Byte) p); | |
| 3524 case TypeCode.SByte : return ToNullableByte((SByte) p); | |
| 3525 case TypeCode.Int16 : return ToNullableByte((Int16) p); | |
| 3526 case TypeCode.Int32 : return ToNullableByte((Int32) p); | |
| 3527 case TypeCode.Int64 : return ToNullableByte((Int64) p); | |
| 3528 case TypeCode.UInt16 : return ToNullableByte((UInt16) p); | |
| 3529 case TypeCode.UInt32 : return ToNullableByte((UInt32) p); | |
| 3530 case TypeCode.UInt64 : return ToNullableByte((UInt64) p); | |
| 3531 case TypeCode.Single : return ToNullableByte((Single) p); | |
| 3532 case TypeCode.Double : return ToNullableByte((Double) p); | |
| 3533 case TypeCode.Decimal : return ToNullableByte((Decimal)p); | |
| 3534 case TypeCode.Char : return ToNullableByte((Char) p); | |
| 3535 case TypeCode.String : return ToNullableByte((String) p); | |
| 3536 case TypeCode.Boolean : return ToNullableByte((Boolean)p); | |
| 3537 } | |
| 3538 | |
| 3539 // Nullable Types | |
| 3540 // | |
| 3541 if (type.IsGenericType) | |
| 3542 { | |
| 3543 if (p is Boolean?) return ToNullableByte((Boolean?) p); | |
| 3544 if (p is Char?) return ToNullableByte((Char?) p); | |
| 3545 if (p is Decimal?) return ToNullableByte((Decimal?) p); | |
| 3546 if (p is Double?) return ToNullableByte((Double?) p); | |
| 3547 if (p is Int16?) return ToNullableByte((Int16?) p); | |
| 3548 if (p is Int32?) return ToNullableByte((Int32?) p); | |
| 3549 if (p is Int64?) return ToNullableByte((Int64?) p); | |
| 3550 if (p is SByte?) return ToNullableByte((SByte?) p); | |
| 3551 if (p is Single?) return ToNullableByte((Single?) p); | |
| 3552 if (p is UInt16?) return ToNullableByte((UInt16?) p); | |
| 3553 if (p is UInt32?) return ToNullableByte((UInt32?) p); | |
| 3554 if (p is UInt64?) return ToNullableByte((UInt64?) p); | |
| 3555 } | |
| 3556 | |
| 3557 // Other Types | |
| 3558 // | |
| 3559 if (p is Binary) return ToNullableByte((Binary) p); | |
| 3560 if (p is Byte[]) return ToNullableByte((Byte[]) p); | |
| 3561 | |
| 3562 #if !SILVERLIGHT | |
| 3563 | |
| 3564 // Sql Types | |
| 3565 // | |
| 3566 if (p is INullable) | |
| 3567 { | |
| 3568 if (p is SqlBoolean) return ToNullableByte((SqlBoolean)p); | |
| 3569 if (p is SqlByte) return ToNullableByte((SqlByte) p); | |
| 3570 if (p is SqlDecimal) return ToNullableByte((SqlDecimal)p); | |
| 3571 if (p is SqlDouble) return ToNullableByte((SqlDouble) p); | |
| 3572 if (p is SqlInt16) return ToNullableByte((SqlInt16) p); | |
| 3573 if (p is SqlInt32) return ToNullableByte((SqlInt32) p); | |
| 3574 if (p is SqlInt64) return ToNullableByte((SqlInt64) p); | |
| 3575 if (p is SqlMoney) return ToNullableByte((SqlMoney) p); | |
| 3576 if (p is SqlSingle) return ToNullableByte((SqlSingle) p); | |
| 3577 if (p is SqlString) return ToNullableByte((SqlString) p); | |
| 3578 } | |
| 3579 | |
| 3580 #endif | |
| 3581 | |
| 3582 throw CreateInvalidCastException(p.GetType(), typeof(Byte?)); | |
| 3583 } | |
| 3584 | |
| 3585 #endregion | |
| 3586 | |
| 3587 #region Char? | |
| 3588 | |
| 3589 // Simple Types | |
| 3590 // | |
| 3591 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3592 public static Char? ToNullableChar(Boolean p) { return p ? (Char?)1 : (Char?)0; } | |
| 3593 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3594 public static Char? ToNullableChar(Byte p) { return checked((Char?)p); } | |
| 3595 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3596 public static Char? ToNullableChar(Char p) { return p; } | |
| 3597 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3598 public static Char? ToNullableChar(Decimal p) { return checked((Char?)p); } | |
| 3599 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3600 public static Char? ToNullableChar(Double p) { return checked((Char?)p); } | |
| 3601 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3602 public static Char? ToNullableChar(Int16 p) { return checked((Char?)p); } | |
| 3603 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3604 public static Char? ToNullableChar(Int32 p) { return checked((Char?)p); } | |
| 3605 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3606 public static Char? ToNullableChar(Int64 p) { return checked((Char?)p); } | |
| 3607 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3608 [CLSCompliant(false)] | |
| 3609 public static Char? ToNullableChar(SByte p) { return checked((Char?)p); } | |
| 3610 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3611 public static Char? ToNullableChar(Single p) { return checked((Char?)p); } | |
| 3612 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3613 public static Char? ToNullableChar(String p) { return string.IsNullOrEmpty(p)? (Char?)0 : p[0]; } | |
| 3614 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3615 [CLSCompliant(false)] | |
| 3616 public static Char? ToNullableChar(UInt16 p) { return checked((Char?)p); } | |
| 3617 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3618 [CLSCompliant(false)] | |
| 3619 public static Char? ToNullableChar(UInt32 p) { return checked((Char?)p); } | |
| 3620 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3621 [CLSCompliant(false)] | |
| 3622 public static Char? ToNullableChar(UInt64 p) { return checked((Char?)p); } | |
| 3623 | |
| 3624 // Nullable Types | |
| 3625 // | |
| 3626 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3627 public static Char? ToNullableChar(Boolean? p) { return p.HasValue && p.Value ? (Char?)1: (Char?)0; } | |
| 3628 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3629 public static Char? ToNullableChar(Byte? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3630 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3631 public static Char? ToNullableChar(Decimal? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3632 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3633 public static Char? ToNullableChar(Double? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3634 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3635 public static Char? ToNullableChar(Int16? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3636 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3637 public static Char? ToNullableChar(Int32? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3638 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3639 public static Char? ToNullableChar(Int64? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3640 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3641 [CLSCompliant(false)] | |
| 3642 public static Char? ToNullableChar(SByte? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3643 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3644 public static Char? ToNullableChar(Single? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3645 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3646 [CLSCompliant(false)] | |
| 3647 public static Char? ToNullableChar(UInt16? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3648 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3649 [CLSCompliant(false)] | |
| 3650 public static Char? ToNullableChar(UInt32? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3651 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3652 [CLSCompliant(false)] | |
| 3653 public static Char? ToNullableChar(UInt64? p) { return p.HasValue ? checked((Char?)p.Value) : (Char?)null; } | |
| 3654 | |
| 3655 // Other Types | |
| 3656 // | |
| 3657 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3658 public static Char? ToNullableChar(Binary p) { return p == null || p.Length == 0 ? (Char?)null : BitConverter.ToChar(p.ToArray(), 0); } | |
| 3659 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3660 public static Char? ToNullableChar(Byte[] p) { return p == null || p.Length == 0 ? (Char?)null : BitConverter.ToChar(p, 0); } | |
| 3661 | |
| 3662 #if !SILVERLIGHT | |
| 3663 | |
| 3664 // Sql Types | |
| 3665 // | |
| 3666 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3667 public static Char? ToNullableChar(SqlBoolean p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3668 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3669 public static Char? ToNullableChar(SqlByte p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3670 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3671 public static Char? ToNullableChar(SqlDecimal p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3672 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3673 public static Char? ToNullableChar(SqlDouble p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3674 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3675 public static Char? ToNullableChar(SqlInt16 p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3676 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3677 public static Char? ToNullableChar(SqlInt32 p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3678 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3679 public static Char? ToNullableChar(SqlInt64 p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3680 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3681 public static Char? ToNullableChar(SqlMoney p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3682 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3683 public static Char? ToNullableChar(SqlSingle p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3684 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3685 public static Char? ToNullableChar(SqlString p) { return p.IsNull ? (Char?)null : ToChar(p.Value); } | |
| 3686 | |
| 3687 #endif | |
| 3688 | |
| 3689 // From Object | |
| 3690 // | |
| 3691 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Char?</c> value.</summary> | |
| 3692 public static Char? ToNullableChar(object p) | |
| 3693 { | |
| 3694 if (p == null) return null; | |
| 3695 | |
| 3696 if (p is Char?) return (Char?)p; | |
| 3697 | |
| 3698 var type = p.GetType(); | |
| 3699 | |
| 3700 // Primitive types | |
| 3701 // | |
| 3702 switch (Type.GetTypeCode(type)) | |
| 3703 { | |
| 3704 case TypeCode.DBNull : return null; | |
| 3705 case TypeCode.Char : return ToNullableChar((Char) p); | |
| 3706 case TypeCode.SByte : return ToNullableChar((SByte) p); | |
| 3707 case TypeCode.Int16 : return ToNullableChar((Int16) p); | |
| 3708 case TypeCode.Int32 : return ToNullableChar((Int32) p); | |
| 3709 case TypeCode.Int64 : return ToNullableChar((Int64) p); | |
| 3710 case TypeCode.Byte : return ToNullableChar((Byte) p); | |
| 3711 case TypeCode.UInt16 : return ToNullableChar((UInt16) p); | |
| 3712 case TypeCode.UInt32 : return ToNullableChar((UInt32) p); | |
| 3713 case TypeCode.UInt64 : return ToNullableChar((UInt64) p); | |
| 3714 case TypeCode.Single : return ToNullableChar((Single) p); | |
| 3715 case TypeCode.Double : return ToNullableChar((Double) p); | |
| 3716 case TypeCode.Decimal : return ToNullableChar((Decimal)p); | |
| 3717 case TypeCode.String : return ToNullableChar((String) p); | |
| 3718 case TypeCode.Boolean : return ToNullableChar((Boolean)p); | |
| 3719 } | |
| 3720 | |
| 3721 // Nullable Types | |
| 3722 // | |
| 3723 if (type.IsGenericType) | |
| 3724 { | |
| 3725 if (p is Boolean?) return ToNullableChar((Boolean?) p); | |
| 3726 if (p is Byte?) return ToNullableChar((Byte?) p); | |
| 3727 if (p is Decimal?) return ToNullableChar((Decimal?) p); | |
| 3728 if (p is Double?) return ToNullableChar((Double?) p); | |
| 3729 if (p is Int16?) return ToNullableChar((Int16?) p); | |
| 3730 if (p is Int32?) return ToNullableChar((Int32?) p); | |
| 3731 if (p is Int64?) return ToNullableChar((Int64?) p); | |
| 3732 if (p is SByte?) return ToNullableChar((SByte?) p); | |
| 3733 if (p is Single?) return ToNullableChar((Single?) p); | |
| 3734 if (p is UInt16?) return ToNullableChar((UInt16?) p); | |
| 3735 if (p is UInt32?) return ToNullableChar((UInt32?) p); | |
| 3736 if (p is UInt64?) return ToNullableChar((UInt64?) p); | |
| 3737 } | |
| 3738 | |
| 3739 // Other Types | |
| 3740 // | |
| 3741 if (p is Binary) return ToNullableChar((Binary) p); | |
| 3742 if (p is Byte[]) return ToNullableChar((Byte[]) p); | |
| 3743 | |
| 3744 #if !SILVERLIGHT | |
| 3745 | |
| 3746 // Sql Types | |
| 3747 // | |
| 3748 if (p is INullable) | |
| 3749 { | |
| 3750 if (p is SqlBoolean) return ToNullableChar((SqlBoolean)p); | |
| 3751 if (p is SqlByte) return ToNullableChar((SqlByte) p); | |
| 3752 if (p is SqlDecimal) return ToNullableChar((SqlDecimal)p); | |
| 3753 if (p is SqlDouble) return ToNullableChar((SqlDouble) p); | |
| 3754 if (p is SqlInt16) return ToNullableChar((SqlInt16) p); | |
| 3755 if (p is SqlInt32) return ToNullableChar((SqlInt32) p); | |
| 3756 if (p is SqlInt64) return ToNullableChar((SqlInt64) p); | |
| 3757 if (p is SqlMoney) return ToNullableChar((SqlMoney) p); | |
| 3758 if (p is SqlSingle) return ToNullableChar((SqlSingle) p); | |
| 3759 if (p is SqlString) return ToNullableChar((SqlString) p); | |
| 3760 } | |
| 3761 | |
| 3762 #endif | |
| 3763 | |
| 3764 throw CreateInvalidCastException(p.GetType(), typeof(Char?)); | |
| 3765 } | |
| 3766 | |
| 3767 #endregion | |
| 3768 | |
| 3769 #region DateTime? | |
| 3770 | |
| 3771 // Simple Types | |
| 3772 // | |
| 3773 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3774 public static DateTime? ToNullableDateTime(DateTime p) { return p; } | |
| 3775 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3776 public static DateTime? ToNullableDateTime(DateTimeOffset p) { return p.LocalDateTime; } | |
| 3777 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3778 public static DateTime? ToNullableDateTime(Double p) { return DateTime.MinValue + TimeSpan.FromDays (p); } | |
| 3779 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3780 public static DateTime? ToNullableDateTime(Int64 p) { return DateTime.MinValue + TimeSpan.FromTicks(p); } | |
| 3781 /// <summary>Converts the value from <c>String</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3782 public static DateTime? ToNullableDateTime(String p) { return p == null ? (DateTime?)null : DateTime.Parse(p, null, DateTimeStyles.NoCurrentDateDefault); } | |
| 3783 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3784 public static DateTime? ToNullableDateTime(TimeSpan p) { return DateTime.MinValue + p; } | |
| 3785 | |
| 3786 // Nullable Types | |
| 3787 // | |
| 3788 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3789 public static DateTime? ToNullableDateTime(DateTimeOffset? p) { return p.HasValue ? p.Value.LocalDateTime : (DateTime?)null; } | |
| 3790 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3791 public static DateTime? ToNullableDateTime(Double? p) { return p.HasValue ? DateTime.MinValue + TimeSpan.FromDays (p.Value): (DateTime?)null; } | |
| 3792 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3793 public static DateTime? ToNullableDateTime(Int64? p) { return p.HasValue ? DateTime.MinValue + TimeSpan.FromTicks(p.Value): (DateTime?)null; } | |
| 3794 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3795 public static DateTime? ToNullableDateTime(TimeSpan? p) { return p.HasValue ? DateTime.MinValue + p.Value : (DateTime?)null; } | |
| 3796 | |
| 3797 // Other Types | |
| 3798 // | |
| 3799 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3800 public static DateTime? ToNullableDateTime(Binary p) { return p == null || p.Length == 0 ? (DateTime?)null : DateTime.FromBinary(ToInt64(p.ToArray())); } | |
| 3801 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3802 public static DateTime? ToNullableDateTime(Byte[] p) { return p == null || p.Length == 0 ? (DateTime?)null : DateTime.FromBinary(ToInt64(p)); } | |
| 3803 | |
| 3804 #if !SILVERLIGHT | |
| 3805 | |
| 3806 // Sql Types | |
| 3807 // | |
| 3808 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3809 public static DateTime? ToNullableDateTime(SqlDateTime p) { return p.IsNull ? (DateTime?)null : p.Value; } | |
| 3810 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3811 public static DateTime? ToNullableDateTime(SqlDouble p) { return p.IsNull ? (DateTime?)null : DateTime.MinValue + TimeSpan.FromDays (p.Value); } | |
| 3812 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3813 public static DateTime? ToNullableDateTime(SqlInt64 p) { return p.IsNull ? (DateTime?)null : DateTime.MinValue + TimeSpan.FromTicks(p.Value); } | |
| 3814 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3815 public static DateTime? ToNullableDateTime(SqlString p) { return p.IsNull ? (DateTime?)null : ToDateTime(p.Value); } | |
| 3816 | |
| 3817 #endif | |
| 3818 | |
| 3819 // From Object | |
| 3820 // | |
| 3821 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>DateTime?</c> value.</summary> | |
| 3822 public static DateTime? ToNullableDateTime(object p) | |
| 3823 { | |
| 3824 if (p == null) return null; | |
| 3825 | |
| 3826 if (p is DateTime?) return (DateTime?)p; | |
| 3827 | |
| 3828 var type = p.GetType(); | |
| 3829 | |
| 3830 // Primitive types | |
| 3831 // | |
| 3832 switch (Type.GetTypeCode(type)) | |
| 3833 { | |
| 3834 case TypeCode.DBNull : return null; | |
| 3835 case TypeCode.DateTime : return ToNullableDateTime((DateTime) p); | |
| 3836 case TypeCode.String : return ToNullableDateTime((String) p); | |
| 3837 case TypeCode.Int64 : return ToNullableDateTime((Int64) p); | |
| 3838 case TypeCode.Double : return ToNullableDateTime((Double) p); | |
| 3839 } | |
| 3840 | |
| 3841 // Simple Types | |
| 3842 // | |
| 3843 if (p is DateTimeOffset) return ToNullableDateTime((DateTimeOffset) p); | |
| 3844 if (p is TimeSpan) return ToNullableDateTime((TimeSpan) p); | |
| 3845 | |
| 3846 // Nullable Types | |
| 3847 // | |
| 3848 if (type.IsGenericType) | |
| 3849 { | |
| 3850 if (p is DateTimeOffset?) return ToNullableDateTime((DateTimeOffset?)p); | |
| 3851 if (p is Double?) return ToNullableDateTime((Double?) p); | |
| 3852 if (p is Int64?) return ToNullableDateTime((Int64?) p); | |
| 3853 if (p is TimeSpan?) return ToNullableDateTime((TimeSpan?) p); | |
| 3854 } | |
| 3855 | |
| 3856 // Other Types | |
| 3857 // | |
| 3858 if (p is Binary) return ToNullableDateTime((Binary) p); | |
| 3859 if (p is Byte[]) return ToNullableDateTime((Byte[]) p); | |
| 3860 | |
| 3861 #if !SILVERLIGHT | |
| 3862 | |
| 3863 // Sql Types | |
| 3864 // | |
| 3865 if (p is INullable) | |
| 3866 { | |
| 3867 if (p is SqlDateTime) return ToNullableDateTime((SqlDateTime) p); | |
| 3868 if (p is SqlDouble) return ToNullableDateTime((SqlDouble) p); | |
| 3869 if (p is SqlInt64) return ToNullableDateTime((SqlInt64) p); | |
| 3870 if (p is SqlString) return ToNullableDateTime((SqlString) p); | |
| 3871 } | |
| 3872 | |
| 3873 #endif | |
| 3874 | |
| 3875 throw CreateInvalidCastException(p.GetType(), typeof(DateTime?)); | |
| 3876 } | |
| 3877 | |
| 3878 #endregion | |
| 3879 | |
| 3880 #region DateTimeOffset? | |
| 3881 | |
| 3882 // Simple Types | |
| 3883 // | |
| 3884 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3885 public static DateTimeOffset? ToNullableDateTimeOffset(DateTime p) { return p; } | |
| 3886 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3887 public static DateTimeOffset? ToNullableDateTimeOffset(DateTimeOffset p) { return p; } | |
| 3888 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3889 public static DateTimeOffset? ToNullableDateTimeOffset(Double p) { return DateTimeOffset.MinValue + TimeSpan.FromDays (p); } | |
| 3890 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3891 public static DateTimeOffset? ToNullableDateTimeOffset(Int64 p) { return DateTimeOffset.MinValue + TimeSpan.FromTicks(p); } | |
| 3892 /// <summary>Converts the value from <c>String</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3893 public static DateTimeOffset? ToNullableDateTimeOffset(String p) { return p == null? (DateTimeOffset?)null : DateTimeOffset.Parse(p); } | |
| 3894 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3895 public static DateTimeOffset? ToNullableDateTimeOffset(TimeSpan p) { return DateTimeOffset.MinValue + p; } | |
| 3896 | |
| 3897 // Nullable Types | |
| 3898 // | |
| 3899 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3900 public static DateTimeOffset? ToNullableDateTimeOffset(DateTime? p) { return p.HasValue ? p.Value : (DateTimeOffset?)null; } | |
| 3901 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3902 public static DateTimeOffset? ToNullableDateTimeOffset(Double? p) { return p.HasValue ? DateTimeOffset.MinValue + TimeSpan.FromDays (p.Value): (DateTimeOffset?)null; } | |
| 3903 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3904 public static DateTimeOffset? ToNullableDateTimeOffset(Int64? p) { return p.HasValue ? DateTimeOffset.MinValue + TimeSpan.FromTicks(p.Value): (DateTimeOffset?)null; } | |
| 3905 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3906 public static DateTimeOffset? ToNullableDateTimeOffset(TimeSpan? p) { return p.HasValue ? DateTimeOffset.MinValue + p.Value : (DateTimeOffset?)null; } | |
| 3907 | |
| 3908 // Other Types | |
| 3909 // | |
| 3910 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3911 public static DateTimeOffset? ToNullableDateTimeOffset(Binary p) { return p == null || p.Length == 0 ? (DateTimeOffset?)null : new DateTimeOffset?(ToDateTime(p.ToArray())); } | |
| 3912 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3913 public static DateTimeOffset? ToNullableDateTimeOffset(Byte[] p) { return p == null || p.Length == 0 ? (DateTimeOffset?)null : new DateTimeOffset?(ToDateTime(p)); } | |
| 3914 | |
| 3915 #if !SILVERLIGHT | |
| 3916 | |
| 3917 // Sql Types | |
| 3918 // | |
| 3919 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3920 public static DateTimeOffset? ToNullableDateTimeOffset(SqlDateTime p) { return p.IsNull ? (DateTimeOffset?)null : p.Value; } | |
| 3921 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3922 public static DateTimeOffset? ToNullableDateTimeOffset(SqlDouble p) { return p.IsNull ? (DateTimeOffset?)null : DateTimeOffset.MinValue + TimeSpan.FromDays (p.Value); } | |
| 3923 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3924 public static DateTimeOffset? ToNullableDateTimeOffset(SqlInt64 p) { return p.IsNull ? (DateTimeOffset?)null : DateTimeOffset.MinValue + TimeSpan.FromTicks(p.Value); } | |
| 3925 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3926 public static DateTimeOffset? ToNullableDateTimeOffset(SqlString p) { return p.IsNull ? (DateTimeOffset?)null : ToDateTimeOffset(p.Value); } | |
| 3927 | |
| 3928 #endif | |
| 3929 | |
| 3930 // From Object | |
| 3931 // | |
| 3932 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>DateTimeOffset?</c> value.</summary> | |
| 3933 public static DateTimeOffset? ToNullableDateTimeOffset(object p) | |
| 3934 { | |
| 3935 if (p == null) return null; | |
| 3936 | |
| 3937 if (p is DateTimeOffset?) return (DateTimeOffset?)p; | |
| 3938 | |
| 3939 var type = p.GetType(); | |
| 3940 | |
| 3941 // Primitive types | |
| 3942 // | |
| 3943 switch (Type.GetTypeCode(type)) | |
| 3944 { | |
| 3945 case TypeCode.DBNull : return null; | |
| 3946 case TypeCode.Int64 : return ToNullableDateTimeOffset((Int64) p); | |
| 3947 case TypeCode.Double : return ToNullableDateTimeOffset((Double) p); | |
| 3948 case TypeCode.DateTime : return ToNullableDateTimeOffset((DateTime) p); | |
| 3949 case TypeCode.String : return ToNullableDateTimeOffset((String) p); | |
| 3950 } | |
| 3951 | |
| 3952 // Simple Types | |
| 3953 // | |
| 3954 if (p is DateTimeOffset) return ToNullableDateTimeOffset((DateTimeOffset)p); | |
| 3955 if (p is TimeSpan) return ToNullableDateTimeOffset((TimeSpan) p); | |
| 3956 | |
| 3957 // Nullable Types | |
| 3958 // | |
| 3959 if (type.IsGenericType) | |
| 3960 { | |
| 3961 if (p is DateTime?) return ToNullableDateTimeOffset((DateTime?) p); | |
| 3962 if (p is Double?) return ToNullableDateTimeOffset((Double?) p); | |
| 3963 if (p is Int64?) return ToNullableDateTimeOffset((Int64?) p); | |
| 3964 if (p is TimeSpan?) return ToNullableDateTimeOffset((TimeSpan?) p); | |
| 3965 } | |
| 3966 | |
| 3967 // Other Types | |
| 3968 // | |
| 3969 if (p is Binary) return ToNullableDateTimeOffset((Binary) p); | |
| 3970 if (p is Byte[]) return ToNullableDateTimeOffset((Byte[]) p); | |
| 3971 | |
| 3972 #if !SILVERLIGHT | |
| 3973 | |
| 3974 // Sql Types | |
| 3975 // | |
| 3976 if (p is INullable) | |
| 3977 { | |
| 3978 if (p is SqlDateTime) return ToNullableDateTimeOffset((SqlDateTime) p); | |
| 3979 if (p is SqlDouble) return ToNullableDateTimeOffset((SqlDouble) p); | |
| 3980 if (p is SqlInt64) return ToNullableDateTimeOffset((SqlInt64) p); | |
| 3981 if (p is SqlString) return ToNullableDateTimeOffset((SqlString) p); | |
| 3982 } | |
| 3983 | |
| 3984 #endif | |
| 3985 | |
| 3986 throw CreateInvalidCastException(p.GetType(), typeof(DateTimeOffset?)); | |
| 3987 } | |
| 3988 | |
| 3989 #endregion | |
| 3990 | |
| 3991 #region Decimal? | |
| 3992 | |
| 3993 // Simple Types | |
| 3994 // | |
| 3995 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 3996 public static Decimal? ToNullableDecimal(Boolean p) { return p ? (Decimal?)1 : (Decimal?)0; } | |
| 3997 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 3998 public static Decimal? ToNullableDecimal(Byte p) { return p; } | |
| 3999 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4000 public static Decimal? ToNullableDecimal(Char p) { return p; } | |
| 4001 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4002 public static Decimal? ToNullableDecimal(Decimal p) { return p; } | |
| 4003 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4004 public static Decimal? ToNullableDecimal(Double p) { return checked((Decimal?)p); } | |
| 4005 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4006 public static Decimal? ToNullableDecimal(Int16 p) { return p; } | |
| 4007 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4008 public static Decimal? ToNullableDecimal(Int32 p) { return p; } | |
| 4009 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4010 public static Decimal? ToNullableDecimal(Int64 p) { return p; } | |
| 4011 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4012 [CLSCompliant(false)] | |
| 4013 public static Decimal? ToNullableDecimal(SByte p) { return p; } | |
| 4014 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4015 public static Decimal? ToNullableDecimal(Single p) { return checked((Decimal?)p); } | |
| 4016 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4017 public static Decimal? ToNullableDecimal(String p) { return p == null? (Decimal?)null : Decimal.Parse(p); } | |
| 4018 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4019 [CLSCompliant(false)] | |
| 4020 public static Decimal? ToNullableDecimal(UInt16 p) { return p; } | |
| 4021 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4022 [CLSCompliant(false)] | |
| 4023 public static Decimal? ToNullableDecimal(UInt32 p) { return p; } | |
| 4024 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4025 [CLSCompliant(false)] | |
| 4026 public static Decimal? ToNullableDecimal(UInt64 p) { return p; } | |
| 4027 | |
| 4028 // Nullable Types | |
| 4029 // | |
| 4030 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4031 public static Decimal? ToNullableDecimal(Boolean? p) { return p.HasValue && p.Value ? (Decimal?)1: (Decimal?)0; } | |
| 4032 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4033 public static Decimal? ToNullableDecimal(Byte? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4034 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4035 public static Decimal? ToNullableDecimal(Char? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4036 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4037 public static Decimal? ToNullableDecimal(Double? p) { return p.HasValue ? checked((Decimal?)p.Value) : (Decimal?)null; } | |
| 4038 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4039 public static Decimal? ToNullableDecimal(Int16? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4040 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4041 public static Decimal? ToNullableDecimal(Int32? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4042 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4043 public static Decimal? ToNullableDecimal(Int64? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4044 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4045 [CLSCompliant(false)] | |
| 4046 public static Decimal? ToNullableDecimal(SByte? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4047 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4048 public static Decimal? ToNullableDecimal(Single? p) { return p.HasValue ? checked((Decimal?)p.Value) : (Decimal?)null; } | |
| 4049 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4050 [CLSCompliant(false)] | |
| 4051 public static Decimal? ToNullableDecimal(UInt16? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4052 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4053 [CLSCompliant(false)] | |
| 4054 public static Decimal? ToNullableDecimal(UInt32? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4055 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4056 [CLSCompliant(false)] | |
| 4057 public static Decimal? ToNullableDecimal(UInt64? p) { return p.HasValue ? p.Value : (Decimal?)null; } | |
| 4058 | |
| 4059 // Other Types | |
| 4060 // | |
| 4061 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4062 public static Decimal? ToNullableDecimal(Binary p) { return p == null || p.Length == 0 ? (Decimal?)null : ToDecimal(p); } | |
| 4063 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4064 public static Decimal? ToNullableDecimal(Byte[] p) { return p == null || p.Length == 0 ? (Decimal?)null : ToDecimal(p); } | |
| 4065 | |
| 4066 #if !SILVERLIGHT | |
| 4067 | |
| 4068 // Sql Types | |
| 4069 // | |
| 4070 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4071 public static Decimal? ToNullableDecimal(SqlBoolean p) { return p.IsNull ? (Decimal?)null : ToDecimal(p.Value); } | |
| 4072 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4073 public static Decimal? ToNullableDecimal(SqlByte p) { return p.IsNull ? (Decimal?)null : p.Value; } | |
| 4074 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4075 public static Decimal? ToNullableDecimal(SqlDecimal p) { return p.IsNull ? (Decimal?)null : p.Value; } | |
| 4076 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4077 public static Decimal? ToNullableDecimal(SqlDouble p) { return p.IsNull ? (Decimal?)null : ToDecimal(p.Value); } | |
| 4078 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4079 public static Decimal? ToNullableDecimal(SqlInt16 p) { return p.IsNull ? (Decimal?)null : p.Value; } | |
| 4080 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4081 public static Decimal? ToNullableDecimal(SqlInt32 p) { return p.IsNull ? (Decimal?)null : p.Value; } | |
| 4082 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4083 public static Decimal? ToNullableDecimal(SqlInt64 p) { return p.IsNull ? (Decimal?)null : p.Value; } | |
| 4084 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4085 public static Decimal? ToNullableDecimal(SqlMoney p) { return p.IsNull ? (Decimal?)null : p.Value; } | |
| 4086 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4087 public static Decimal? ToNullableDecimal(SqlSingle p) { return p.IsNull ? (Decimal?)null : ToDecimal(p.Value); } | |
| 4088 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4089 public static Decimal? ToNullableDecimal(SqlString p) { return p.IsNull ? (Decimal?)null : ToDecimal(p.Value); } | |
| 4090 | |
| 4091 #endif | |
| 4092 | |
| 4093 // From Object | |
| 4094 // | |
| 4095 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Decimal?</c> value.</summary> | |
| 4096 public static Decimal? ToNullableDecimal(object p) | |
| 4097 { | |
| 4098 if (p == null) return null; | |
| 4099 | |
| 4100 if (p is Decimal?) return (Decimal?)p; | |
| 4101 | |
| 4102 var type = p.GetType(); | |
| 4103 | |
| 4104 // Primitive types | |
| 4105 // | |
| 4106 switch (Type.GetTypeCode(type)) | |
| 4107 { | |
| 4108 case TypeCode.DBNull : return null; | |
| 4109 case TypeCode.SByte : return ToNullableDecimal((SByte) p); | |
| 4110 case TypeCode.Int16 : return ToNullableDecimal((Int16) p); | |
| 4111 case TypeCode.Int32 : return ToNullableDecimal((Int32) p); | |
| 4112 case TypeCode.Int64 : return ToNullableDecimal((Int64) p); | |
| 4113 case TypeCode.Byte : return ToNullableDecimal((Byte) p); | |
| 4114 case TypeCode.UInt16 : return ToNullableDecimal((UInt16) p); | |
| 4115 case TypeCode.UInt32 : return ToNullableDecimal((UInt32) p); | |
| 4116 case TypeCode.Char : return ToNullableDecimal((Char) p); | |
| 4117 case TypeCode.UInt64 : return ToNullableDecimal((UInt64) p); | |
| 4118 case TypeCode.Decimal : return ToNullableDecimal((Decimal) p); | |
| 4119 case TypeCode.Single : return ToNullableDecimal((Single) p); | |
| 4120 case TypeCode.Double : return ToNullableDecimal((Double) p); | |
| 4121 case TypeCode.String : return ToNullableDecimal((String) p); | |
| 4122 case TypeCode.Boolean : return ToNullableDecimal((Boolean) p); | |
| 4123 } | |
| 4124 | |
| 4125 // Nullable Types | |
| 4126 // | |
| 4127 if (type.IsGenericType) | |
| 4128 { | |
| 4129 if (p is Boolean?) return ToNullableDecimal((Boolean?) p); | |
| 4130 if (p is Byte?) return ToNullableDecimal((Byte?) p); | |
| 4131 if (p is Char?) return ToNullableDecimal((Char?) p); | |
| 4132 if (p is Double?) return ToNullableDecimal((Double?) p); | |
| 4133 if (p is Int16?) return ToNullableDecimal((Int16?) p); | |
| 4134 if (p is Int32?) return ToNullableDecimal((Int32?) p); | |
| 4135 if (p is Int64?) return ToNullableDecimal((Int64?) p); | |
| 4136 if (p is SByte?) return ToNullableDecimal((SByte?) p); | |
| 4137 if (p is Single?) return ToNullableDecimal((Single?) p); | |
| 4138 if (p is UInt16?) return ToNullableDecimal((UInt16?) p); | |
| 4139 if (p is UInt32?) return ToNullableDecimal((UInt32?) p); | |
| 4140 if (p is UInt64?) return ToNullableDecimal((UInt64?) p); | |
| 4141 } | |
| 4142 | |
| 4143 // Other Types | |
| 4144 // | |
| 4145 if (p is Binary) return ToNullableDecimal((Binary) p); | |
| 4146 if (p is Byte[]) return ToNullableDecimal((Byte[]) p); | |
| 4147 | |
| 4148 #if !SILVERLIGHT | |
| 4149 | |
| 4150 // Sql Types | |
| 4151 // | |
| 4152 if (p is INullable) | |
| 4153 { | |
| 4154 if (p is SqlBoolean) return ToNullableDecimal((SqlBoolean)p); | |
| 4155 if (p is SqlByte) return ToNullableDecimal((SqlByte) p); | |
| 4156 if (p is SqlDecimal) return ToNullableDecimal((SqlDecimal)p); | |
| 4157 if (p is SqlDouble) return ToNullableDecimal((SqlDouble) p); | |
| 4158 if (p is SqlInt16) return ToNullableDecimal((SqlInt16) p); | |
| 4159 if (p is SqlInt32) return ToNullableDecimal((SqlInt32) p); | |
| 4160 if (p is SqlInt64) return ToNullableDecimal((SqlInt64) p); | |
| 4161 if (p is SqlMoney) return ToNullableDecimal((SqlMoney) p); | |
| 4162 if (p is SqlSingle) return ToNullableDecimal((SqlSingle) p); | |
| 4163 if (p is SqlString) return ToNullableDecimal((SqlString) p); | |
| 4164 } | |
| 4165 | |
| 4166 #endif | |
| 4167 | |
| 4168 throw CreateInvalidCastException(p.GetType(), typeof(Decimal?)); | |
| 4169 } | |
| 4170 | |
| 4171 #endregion | |
| 4172 | |
| 4173 #region Double? | |
| 4174 | |
| 4175 // Simple Types | |
| 4176 // | |
| 4177 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4178 public static Double? ToNullableDouble(Boolean p) { return p ? (Double?)1 : (Double?)0; } | |
| 4179 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4180 public static Double? ToNullableDouble(Byte p) { return p; } | |
| 4181 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4182 public static Double? ToNullableDouble(Char p) { return p; } | |
| 4183 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4184 public static Double? ToNullableDouble(DateTime p) { return (p - DateTime.MinValue).TotalDays; } | |
| 4185 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4186 public static Double? ToNullableDouble(DateTimeOffset p) { return (p - DateTimeOffset.MinValue).TotalDays; } | |
| 4187 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4188 public static Double? ToNullableDouble(Decimal p) { return checked((Double?)p); } | |
| 4189 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4190 public static Double? ToNullableDouble(Double p) { return p; } | |
| 4191 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4192 public static Double? ToNullableDouble(Int16 p) { return p; } | |
| 4193 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4194 public static Double? ToNullableDouble(Int32 p) { return p; } | |
| 4195 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4196 public static Double? ToNullableDouble(Int64 p) { return p; } | |
| 4197 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4198 [CLSCompliant(false)] | |
| 4199 public static Double? ToNullableDouble(SByte p) { return p; } | |
| 4200 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4201 public static Double? ToNullableDouble(Single p) { return p; } | |
| 4202 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4203 public static Double? ToNullableDouble(String p) { return p == null? (Double?)null : Double.Parse(p); } | |
| 4204 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4205 public static Double? ToNullableDouble(TimeSpan p) { return p.TotalDays; } | |
| 4206 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4207 [CLSCompliant(false)] | |
| 4208 public static Double? ToNullableDouble(UInt16 p) { return p; } | |
| 4209 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4210 [CLSCompliant(false)] | |
| 4211 public static Double? ToNullableDouble(UInt32 p) { return p; } | |
| 4212 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4213 [CLSCompliant(false)] | |
| 4214 public static Double? ToNullableDouble(UInt64 p) { return p; } | |
| 4215 | |
| 4216 // Nullable Types | |
| 4217 // | |
| 4218 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4219 public static Double? ToNullableDouble(Boolean? p) { return p.HasValue && p.Value ? (Double?)1: (Double?)0; } | |
| 4220 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4221 public static Double? ToNullableDouble(Byte? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4222 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4223 public static Double? ToNullableDouble(Char? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4224 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4225 public static Double? ToNullableDouble(DateTime? p) { return p.HasValue ? (p.Value - DateTime.MinValue).TotalDays : (Double?)null; } | |
| 4226 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4227 public static Double? ToNullableDouble(DateTimeOffset? p) { return p.HasValue ? (p.Value - DateTimeOffset.MinValue).TotalDays : (Double?)null; } | |
| 4228 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4229 public static Double? ToNullableDouble(Decimal? p) { return p.HasValue ? checked((Double?)p.Value) : (Double?)null; } | |
| 4230 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4231 public static Double? ToNullableDouble(Int16? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4232 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4233 public static Double? ToNullableDouble(Int32? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4234 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4235 public static Double? ToNullableDouble(Int64? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4236 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4237 [CLSCompliant(false)] | |
| 4238 public static Double? ToNullableDouble(SByte? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4239 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4240 public static Double? ToNullableDouble(Single? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4241 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4242 public static Double? ToNullableDouble(TimeSpan? p) { return p.HasValue ? p.Value.TotalDays : (Double?)null; } | |
| 4243 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4244 [CLSCompliant(false)] | |
| 4245 public static Double? ToNullableDouble(UInt16? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4246 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4247 [CLSCompliant(false)] | |
| 4248 public static Double? ToNullableDouble(UInt32? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4249 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4250 [CLSCompliant(false)] | |
| 4251 public static Double? ToNullableDouble(UInt64? p) { return p.HasValue ? p.Value : (Double?)null; } | |
| 4252 | |
| 4253 // Other Types | |
| 4254 // | |
| 4255 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4256 public static Double? ToNullableDouble(Binary p) { return p == null || p.Length == 0 ? (Double?)null : BitConverter.ToDouble(p.ToArray(), 0); } | |
| 4257 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4258 public static Double? ToNullableDouble(Byte[] p) { return p == null || p.Length == 0 ? (Double?)null : BitConverter.ToDouble(p, 0); } | |
| 4259 | |
| 4260 #if !SILVERLIGHT | |
| 4261 | |
| 4262 // Sql Types | |
| 4263 // | |
| 4264 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4265 public static Double? ToNullableDouble(SqlBoolean p) { return p.IsNull ? (Double?)null : ToDouble(p.Value); } | |
| 4266 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4267 public static Double? ToNullableDouble(SqlByte p) { return p.IsNull ? (Double?)null : p.Value; } | |
| 4268 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4269 public static Double? ToNullableDouble(SqlDateTime p) { return p.IsNull ? (Double?)null : ToDouble(p.Value); } | |
| 4270 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4271 public static Double? ToNullableDouble(SqlDecimal p) { return p.IsNull ? (Double?)null : ToDouble(p.Value); } | |
| 4272 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4273 public static Double? ToNullableDouble(SqlDouble p) { return p.IsNull ? (Double?)null : p.Value; } | |
| 4274 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4275 public static Double? ToNullableDouble(SqlInt16 p) { return p.IsNull ? (Double?)null : p.Value; } | |
| 4276 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4277 public static Double? ToNullableDouble(SqlInt32 p) { return p.IsNull ? (Double?)null : p.Value; } | |
| 4278 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4279 public static Double? ToNullableDouble(SqlInt64 p) { return p.IsNull ? (Double?)null : p.Value; } | |
| 4280 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4281 public static Double? ToNullableDouble(SqlMoney p) { return p.IsNull ? (Double?)null : ToDouble(p.Value); } | |
| 4282 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4283 public static Double? ToNullableDouble(SqlSingle p) { return p.IsNull ? (Double?)null : p.Value; } | |
| 4284 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4285 public static Double? ToNullableDouble(SqlString p) { return p.IsNull ? (Double?)null : ToDouble(p.Value); } | |
| 4286 | |
| 4287 #endif | |
| 4288 | |
| 4289 // From Object | |
| 4290 // | |
| 4291 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Double?</c> value.</summary> | |
| 4292 public static Double? ToNullableDouble(object p) | |
| 4293 { | |
| 4294 if (p == null) return null; | |
| 4295 | |
| 4296 if (p is Double?) return (Double?)p; | |
| 4297 | |
| 4298 var type = p.GetType(); | |
| 4299 | |
| 4300 // Primitive types | |
| 4301 // | |
| 4302 switch (Type.GetTypeCode(type)) | |
| 4303 { | |
| 4304 case TypeCode.DBNull : return null; | |
| 4305 case TypeCode.DateTime : return ToNullableDouble((DateTime)p); | |
| 4306 case TypeCode.SByte : return ToNullableDouble((SByte) p); | |
| 4307 case TypeCode.Int16 : return ToNullableDouble((Int16) p); | |
| 4308 case TypeCode.Int32 : return ToNullableDouble((Int32) p); | |
| 4309 case TypeCode.Int64 : return ToNullableDouble((Int64) p); | |
| 4310 case TypeCode.Byte : return ToNullableDouble((Byte) p); | |
| 4311 case TypeCode.UInt16 : return ToNullableDouble((UInt16) p); | |
| 4312 case TypeCode.UInt32 : return ToNullableDouble((UInt32) p); | |
| 4313 case TypeCode.Char : return ToNullableDouble((Char) p); | |
| 4314 case TypeCode.UInt64 : return ToNullableDouble((UInt64) p); | |
| 4315 case TypeCode.Single : return ToNullableDouble((Single) p); | |
| 4316 case TypeCode.Double : return ToNullableDouble((Double) p); | |
| 4317 case TypeCode.Decimal : return ToNullableDouble((Decimal) p); | |
| 4318 case TypeCode.String : return ToNullableDouble((String) p); | |
| 4319 case TypeCode.Boolean : return ToNullableDouble((Boolean) p); | |
| 4320 } | |
| 4321 | |
| 4322 // Simple Types | |
| 4323 // | |
| 4324 if (p is DateTimeOffset) return ToNullableDouble((DateTimeOffset) p); | |
| 4325 if (p is TimeSpan) return ToNullableDouble((TimeSpan) p); | |
| 4326 | |
| 4327 // Nullable Types | |
| 4328 // | |
| 4329 if (type.IsGenericType) | |
| 4330 { | |
| 4331 if (p is Boolean?) return ToNullableDouble((Boolean?) p); | |
| 4332 if (p is Byte?) return ToNullableDouble((Byte?) p); | |
| 4333 if (p is Char?) return ToNullableDouble((Char?) p); | |
| 4334 if (p is DateTime?) return ToNullableDouble((DateTime?) p); | |
| 4335 if (p is DateTimeOffset?) return ToNullableDouble((DateTimeOffset?)p); | |
| 4336 if (p is Decimal?) return ToNullableDouble((Decimal?) p); | |
| 4337 if (p is Int16?) return ToNullableDouble((Int16?) p); | |
| 4338 if (p is Int32?) return ToNullableDouble((Int32?) p); | |
| 4339 if (p is Int64?) return ToNullableDouble((Int64?) p); | |
| 4340 if (p is SByte?) return ToNullableDouble((SByte?) p); | |
| 4341 if (p is Single?) return ToNullableDouble((Single?) p); | |
| 4342 if (p is TimeSpan?) return ToNullableDouble((TimeSpan?) p); | |
| 4343 if (p is UInt16?) return ToNullableDouble((UInt16?) p); | |
| 4344 if (p is UInt32?) return ToNullableDouble((UInt32?) p); | |
| 4345 if (p is UInt64?) return ToNullableDouble((UInt64?) p); | |
| 4346 } | |
| 4347 | |
| 4348 // Other Types | |
| 4349 // | |
| 4350 if (p is Binary) return ToNullableDouble((Binary) p); | |
| 4351 if (p is Byte[]) return ToNullableDouble((Byte[]) p); | |
| 4352 | |
| 4353 #if !SILVERLIGHT | |
| 4354 | |
| 4355 // Sql Types | |
| 4356 // | |
| 4357 if (p is INullable) | |
| 4358 { | |
| 4359 if (p is SqlBoolean) return ToNullableDouble((SqlBoolean) p); | |
| 4360 if (p is SqlByte) return ToNullableDouble((SqlByte) p); | |
| 4361 if (p is SqlDateTime) return ToNullableDouble((SqlDateTime) p); | |
| 4362 if (p is SqlDecimal) return ToNullableDouble((SqlDecimal) p); | |
| 4363 if (p is SqlDouble) return ToNullableDouble((SqlDouble) p); | |
| 4364 if (p is SqlInt16) return ToNullableDouble((SqlInt16) p); | |
| 4365 if (p is SqlInt32) return ToNullableDouble((SqlInt32) p); | |
| 4366 if (p is SqlInt64) return ToNullableDouble((SqlInt64) p); | |
| 4367 if (p is SqlMoney) return ToNullableDouble((SqlMoney) p); | |
| 4368 if (p is SqlSingle) return ToNullableDouble((SqlSingle) p); | |
| 4369 if (p is SqlString) return ToNullableDouble((SqlString) p); | |
| 4370 } | |
| 4371 | |
| 4372 #endif | |
| 4373 | |
| 4374 throw CreateInvalidCastException(p.GetType(), typeof(Double?)); | |
| 4375 } | |
| 4376 | |
| 4377 #endregion | |
| 4378 | |
| 4379 #region Guid? | |
| 4380 | |
| 4381 // Simple Types | |
| 4382 // | |
| 4383 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4384 public static Guid? ToNullableGuid(Guid p) { return p; } | |
| 4385 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4386 public static Guid? ToNullableGuid(String p) { return p == null ? (Guid?)null : new Guid(p); } | |
| 4387 | |
| 4388 // Other Types | |
| 4389 // | |
| 4390 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4391 public static Guid? ToNullableGuid(Binary p) { return p == null ? (Guid?)null : new Guid(p.ToArray()); } | |
| 4392 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4393 public static Guid? ToNullableGuid(Byte[] p) { return p == null ? (Guid?)null : new Guid(p); } | |
| 4394 /// <summary>Converts the value from <c>Type</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4395 public static Guid? ToNullableGuid(Type p) { return p == null ? (Guid?)null : p.GUID; } | |
| 4396 | |
| 4397 #if !SILVERLIGHT | |
| 4398 | |
| 4399 // Sql Types | |
| 4400 // | |
| 4401 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4402 public static Guid? ToNullableGuid(SqlBinary p) { return p.IsNull ? (Guid?)null : p.ToSqlGuid().Value; } | |
| 4403 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4404 public static Guid? ToNullableGuid(SqlGuid p) { return p.IsNull ? (Guid?)null : p.Value; } | |
| 4405 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4406 public static Guid? ToNullableGuid(SqlString p) { return p.IsNull ? (Guid?)null : new Guid(p.Value); } | |
| 4407 | |
| 4408 #endif | |
| 4409 | |
| 4410 // From Object | |
| 4411 // | |
| 4412 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Guid?</c> value.</summary> | |
| 4413 public static Guid? ToNullableGuid(object p) | |
| 4414 { | |
| 4415 if (p == null) return null; | |
| 4416 | |
| 4417 if (p is Guid?) return (Guid?)p; | |
| 4418 | |
| 4419 var type = p.GetType(); | |
| 4420 | |
| 4421 // Primitive types | |
| 4422 // | |
| 4423 switch (Type.GetTypeCode(type)) | |
| 4424 { | |
| 4425 case TypeCode.DBNull : return null; | |
| 4426 case TypeCode.String : return ToNullableGuid((String)p); | |
| 4427 } | |
| 4428 | |
| 4429 // Simple Types | |
| 4430 // | |
| 4431 if (p is Guid) return ToNullableGuid((Guid) p); | |
| 4432 | |
| 4433 // Other Types | |
| 4434 // | |
| 4435 if (p is Binary) return ToNullableGuid((Binary) p); | |
| 4436 if (p is Byte[]) return ToNullableGuid((Byte[]) p); | |
| 4437 if (p is Type) return ToNullableGuid((Type) p); | |
| 4438 | |
| 4439 #if !SILVERLIGHT | |
| 4440 | |
| 4441 // Sql Types | |
| 4442 // | |
| 4443 if (p is INullable) | |
| 4444 { | |
| 4445 if (p is SqlBinary) return ToNullableGuid((SqlBinary)p); | |
| 4446 if (p is SqlGuid) return ToNullableGuid((SqlGuid) p); | |
| 4447 if (p is SqlString) return ToNullableGuid((SqlString)p); | |
| 4448 } | |
| 4449 | |
| 4450 #endif | |
| 4451 | |
| 4452 throw CreateInvalidCastException(p.GetType(), typeof(Guid?)); | |
| 4453 } | |
| 4454 | |
| 4455 #endregion | |
| 4456 | |
| 4457 #region Int16? | |
| 4458 | |
| 4459 // Simple Types | |
| 4460 // | |
| 4461 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4462 public static Int16? ToNullableInt16(Boolean p) { return p ? (Int16?)1 : (Int16?)0; } | |
| 4463 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4464 public static Int16? ToNullableInt16(Byte p) { return p; } | |
| 4465 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4466 public static Int16? ToNullableInt16(Char p) { return checked((Int16?)p); } | |
| 4467 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4468 public static Int16? ToNullableInt16(Decimal p) { return checked((Int16?)p); } | |
| 4469 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4470 public static Int16? ToNullableInt16(Double p) { return checked((Int16?)p); } | |
| 4471 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4472 public static Int16? ToNullableInt16(Int16 p) { return p; } | |
| 4473 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4474 public static Int16? ToNullableInt16(Int32 p) { return checked((Int16?)p); } | |
| 4475 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4476 public static Int16? ToNullableInt16(Int64 p) { return checked((Int16?)p); } | |
| 4477 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4478 [CLSCompliant(false)] | |
| 4479 public static Int16? ToNullableInt16(SByte p) { return p; } | |
| 4480 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4481 public static Int16? ToNullableInt16(Single p) { return checked((Int16?)p); } | |
| 4482 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4483 public static Int16? ToNullableInt16(String p) { return p == null? (Int16?)null : Int16.Parse(p); } | |
| 4484 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4485 [CLSCompliant(false)] | |
| 4486 public static Int16? ToNullableInt16(UInt16 p) { return checked((Int16?)p); } | |
| 4487 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4488 [CLSCompliant(false)] | |
| 4489 public static Int16? ToNullableInt16(UInt32 p) { return checked((Int16?)p); } | |
| 4490 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4491 [CLSCompliant(false)] | |
| 4492 public static Int16? ToNullableInt16(UInt64 p) { return checked((Int16?)p); } | |
| 4493 | |
| 4494 // Nullable Types | |
| 4495 // | |
| 4496 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4497 public static Int16? ToNullableInt16(Boolean? p) { return p.HasValue && p.Value ? (Int16?)1: (Int16?)0; } | |
| 4498 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4499 public static Int16? ToNullableInt16(Byte? p) { return p.HasValue ? p.Value : (Int16?)null; } | |
| 4500 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4501 public static Int16? ToNullableInt16(Char? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4502 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4503 public static Int16? ToNullableInt16(Decimal? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4504 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4505 public static Int16? ToNullableInt16(Double? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4506 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4507 public static Int16? ToNullableInt16(Int32? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4508 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4509 public static Int16? ToNullableInt16(Int64? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4510 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4511 [CLSCompliant(false)] | |
| 4512 public static Int16? ToNullableInt16(SByte? p) { return p.HasValue ? p.Value : (Int16?)null; } | |
| 4513 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4514 public static Int16? ToNullableInt16(Single? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4515 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4516 [CLSCompliant(false)] | |
| 4517 public static Int16? ToNullableInt16(UInt16? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4518 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4519 [CLSCompliant(false)] | |
| 4520 public static Int16? ToNullableInt16(UInt32? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4521 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4522 [CLSCompliant(false)] | |
| 4523 public static Int16? ToNullableInt16(UInt64? p) { return p.HasValue ? checked((Int16?)p.Value) : (Int16?)null; } | |
| 4524 | |
| 4525 // Other Types | |
| 4526 // | |
| 4527 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4528 public static Int16? ToNullableInt16(Binary p) { return p == null || p.Length == 0 ? (Int16?)null : BitConverter.ToInt16(p.ToArray(), 0); } | |
| 4529 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4530 public static Int16? ToNullableInt16(Byte[] p) { return p == null || p.Length == 0 ? (Int16?)null : BitConverter.ToInt16(p, 0); } | |
| 4531 | |
| 4532 #if !SILVERLIGHT | |
| 4533 | |
| 4534 // Sql Types | |
| 4535 // | |
| 4536 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4537 public static Int16? ToNullableInt16(SqlBoolean p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4538 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4539 public static Int16? ToNullableInt16(SqlByte p) { return p.IsNull ? (Int16?)null : p.Value; } | |
| 4540 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4541 public static Int16? ToNullableInt16(SqlDecimal p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4542 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4543 public static Int16? ToNullableInt16(SqlDouble p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4544 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4545 public static Int16? ToNullableInt16(SqlInt16 p) { return p.IsNull ? (Int16?)null : p.Value; } | |
| 4546 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4547 public static Int16? ToNullableInt16(SqlInt32 p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4548 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4549 public static Int16? ToNullableInt16(SqlInt64 p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4550 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4551 public static Int16? ToNullableInt16(SqlMoney p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4552 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4553 public static Int16? ToNullableInt16(SqlSingle p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4554 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4555 public static Int16? ToNullableInt16(SqlString p) { return p.IsNull ? (Int16?)null : ToInt16(p.Value); } | |
| 4556 | |
| 4557 #endif | |
| 4558 | |
| 4559 // From Object | |
| 4560 // | |
| 4561 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Int16?</c> value.</summary> | |
| 4562 public static Int16? ToNullableInt16(object p) | |
| 4563 { | |
| 4564 if (p == null) return null; | |
| 4565 | |
| 4566 if (p is Int16?) return (Int16?)p; | |
| 4567 | |
| 4568 var type = p.GetType(); | |
| 4569 | |
| 4570 // Primitive types | |
| 4571 // | |
| 4572 switch (Type.GetTypeCode(type)) | |
| 4573 { | |
| 4574 case TypeCode.DBNull : return null; | |
| 4575 case TypeCode.SByte : return ToNullableInt16((SByte) p); | |
| 4576 case TypeCode.Int16 : return ToNullableInt16((Int16) p); | |
| 4577 case TypeCode.Byte : return ToNullableInt16((Byte) p); | |
| 4578 case TypeCode.Int32 : return ToNullableInt16((Int32) p); | |
| 4579 case TypeCode.Int64 : return ToNullableInt16((Int64) p); | |
| 4580 case TypeCode.UInt16 : return ToNullableInt16((UInt16) p); | |
| 4581 case TypeCode.UInt32 : return ToNullableInt16((UInt32) p); | |
| 4582 case TypeCode.UInt64 : return ToNullableInt16((UInt64) p); | |
| 4583 case TypeCode.Single : return ToNullableInt16((Single) p); | |
| 4584 case TypeCode.Double : return ToNullableInt16((Double) p); | |
| 4585 case TypeCode.Decimal : return ToNullableInt16((Decimal)p); | |
| 4586 case TypeCode.Char : return ToNullableInt16((Char) p); | |
| 4587 case TypeCode.String : return ToNullableInt16((String) p); | |
| 4588 case TypeCode.Boolean : return ToNullableInt16((Boolean)p); | |
| 4589 } | |
| 4590 | |
| 4591 // Nullable Types | |
| 4592 // | |
| 4593 if (type.IsGenericType) | |
| 4594 { | |
| 4595 if (p is Boolean?) return ToNullableInt16((Boolean?) p); | |
| 4596 if (p is Byte?) return ToNullableInt16((Byte?) p); | |
| 4597 if (p is Char?) return ToNullableInt16((Char?) p); | |
| 4598 if (p is Decimal?) return ToNullableInt16((Decimal?) p); | |
| 4599 if (p is Double?) return ToNullableInt16((Double?) p); | |
| 4600 if (p is Int32?) return ToNullableInt16((Int32?) p); | |
| 4601 if (p is Int64?) return ToNullableInt16((Int64?) p); | |
| 4602 if (p is SByte?) return ToNullableInt16((SByte?) p); | |
| 4603 if (p is Single?) return ToNullableInt16((Single?) p); | |
| 4604 if (p is UInt16?) return ToNullableInt16((UInt16?) p); | |
| 4605 if (p is UInt32?) return ToNullableInt16((UInt32?) p); | |
| 4606 if (p is UInt64?) return ToNullableInt16((UInt64?) p); | |
| 4607 } | |
| 4608 | |
| 4609 // Other Types | |
| 4610 // | |
| 4611 if (p is Binary) return ToNullableInt16((Binary) p); | |
| 4612 if (p is Byte[]) return ToNullableInt16((Byte[]) p); | |
| 4613 | |
| 4614 #if !SILVERLIGHT | |
| 4615 | |
| 4616 // Sql Types | |
| 4617 // | |
| 4618 if (p is INullable) | |
| 4619 { | |
| 4620 if (p is SqlBoolean) return ToNullableInt16((SqlBoolean)p); | |
| 4621 if (p is SqlByte) return ToNullableInt16((SqlByte) p); | |
| 4622 if (p is SqlDecimal) return ToNullableInt16((SqlDecimal)p); | |
| 4623 if (p is SqlDouble) return ToNullableInt16((SqlDouble) p); | |
| 4624 if (p is SqlInt16) return ToNullableInt16((SqlInt16) p); | |
| 4625 if (p is SqlInt32) return ToNullableInt16((SqlInt32) p); | |
| 4626 if (p is SqlInt64) return ToNullableInt16((SqlInt64) p); | |
| 4627 if (p is SqlMoney) return ToNullableInt16((SqlMoney) p); | |
| 4628 if (p is SqlSingle) return ToNullableInt16((SqlSingle) p); | |
| 4629 if (p is SqlString) return ToNullableInt16((SqlString) p); | |
| 4630 } | |
| 4631 | |
| 4632 #endif | |
| 4633 | |
| 4634 throw CreateInvalidCastException(p.GetType(), typeof(Int16?)); | |
| 4635 } | |
| 4636 | |
| 4637 #endregion | |
| 4638 | |
| 4639 #region Int32? | |
| 4640 | |
| 4641 // Simple Types | |
| 4642 // | |
| 4643 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4644 public static Int32? ToNullableInt32(Boolean p) { return p ? (Int32?)1 : (Int32?)0; } | |
| 4645 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4646 public static Int32? ToNullableInt32(Byte p) { return p; } | |
| 4647 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4648 public static Int32? ToNullableInt32(Char p) { return p; } | |
| 4649 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4650 public static Int32? ToNullableInt32(Decimal p) { return checked((Int32?)p); } | |
| 4651 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4652 public static Int32? ToNullableInt32(Double p) { return checked((Int32?)p); } | |
| 4653 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4654 public static Int32? ToNullableInt32(Int16 p) { return p; } | |
| 4655 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4656 public static Int32? ToNullableInt32(Int32 p) { return p; } | |
| 4657 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4658 public static Int32? ToNullableInt32(Int64 p) { return checked((Int32?)p); } | |
| 4659 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4660 [CLSCompliant(false)] | |
| 4661 public static Int32? ToNullableInt32(SByte p) { return p; } | |
| 4662 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4663 public static Int32? ToNullableInt32(Single p) { return checked((Int32?)p); } | |
| 4664 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4665 public static Int32? ToNullableInt32(String p) { return p == null? (Int32?)null : Int32.Parse(p); } | |
| 4666 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4667 [CLSCompliant(false)] | |
| 4668 public static Int32? ToNullableInt32(UInt16 p) { return p; } | |
| 4669 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4670 [CLSCompliant(false)] | |
| 4671 public static Int32? ToNullableInt32(UInt32 p) { return checked((Int32?)p); } | |
| 4672 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4673 [CLSCompliant(false)] | |
| 4674 public static Int32? ToNullableInt32(UInt64 p) { return checked((Int32?)p); } | |
| 4675 | |
| 4676 // Nullable Types | |
| 4677 // | |
| 4678 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4679 public static Int32? ToNullableInt32(Boolean? p) { return p.HasValue && p.Value ? (Int32?)1: (Int32?)0; } | |
| 4680 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4681 public static Int32? ToNullableInt32(Byte? p) { return p.HasValue ? p.Value : (Int32?)null; } | |
| 4682 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4683 public static Int32? ToNullableInt32(Char? p) { return p.HasValue ? p.Value : (Int32?)null; } | |
| 4684 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4685 public static Int32? ToNullableInt32(Decimal? p) { return p.HasValue ? checked((Int32?)p.Value) : (Int32?)null; } | |
| 4686 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4687 public static Int32? ToNullableInt32(Double? p) { return p.HasValue ? checked((Int32?)p.Value) : (Int32?)null; } | |
| 4688 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4689 public static Int32? ToNullableInt32(Int16? p) { return p.HasValue ? p.Value : (Int32?)null; } | |
| 4690 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4691 public static Int32? ToNullableInt32(Int64? p) { return p.HasValue ? checked((Int32?)p.Value) : (Int32?)null; } | |
| 4692 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4693 [CLSCompliant(false)] | |
| 4694 public static Int32? ToNullableInt32(SByte? p) { return p.HasValue ? p.Value : (Int32?)null; } | |
| 4695 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4696 public static Int32? ToNullableInt32(Single? p) { return p.HasValue ? checked((Int32?)p.Value) : (Int32?)null; } | |
| 4697 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4698 [CLSCompliant(false)] | |
| 4699 public static Int32? ToNullableInt32(UInt16? p) { return p.HasValue ? p.Value : (Int32?)null; } | |
| 4700 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4701 [CLSCompliant(false)] | |
| 4702 public static Int32? ToNullableInt32(UInt32? p) { return p.HasValue ? checked((Int32?)p.Value) : (Int32?)null; } | |
| 4703 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4704 [CLSCompliant(false)] | |
| 4705 public static Int32? ToNullableInt32(UInt64? p) { return p.HasValue ? checked((Int32?)p.Value) : (Int32?)null; } | |
| 4706 | |
| 4707 // Other Types | |
| 4708 // | |
| 4709 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4710 public static Int32? ToNullableInt32(Binary p) { return p == null || p.Length == 0 ? (Int32?)null : BitConverter.ToInt32(p.ToArray(), 0); } | |
| 4711 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4712 public static Int32? ToNullableInt32(Byte[] p) { return p == null || p.Length == 0 ? (Int32?)null : BitConverter.ToInt32(p, 0); } | |
| 4713 | |
| 4714 #if !SILVERLIGHT | |
| 4715 | |
| 4716 // Sql Types | |
| 4717 // | |
| 4718 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4719 public static Int32? ToNullableInt32(SqlBoolean p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4720 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4721 public static Int32? ToNullableInt32(SqlByte p) { return p.IsNull ? (Int32?)null : p.Value; } | |
| 4722 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4723 public static Int32? ToNullableInt32(SqlDecimal p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4724 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4725 public static Int32? ToNullableInt32(SqlDouble p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4726 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4727 public static Int32? ToNullableInt32(SqlInt16 p) { return p.IsNull ? (Int32?)null : p.Value; } | |
| 4728 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4729 public static Int32? ToNullableInt32(SqlInt32 p) { return p.IsNull ? (Int32?)null : p.Value; } | |
| 4730 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4731 public static Int32? ToNullableInt32(SqlInt64 p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4732 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4733 public static Int32? ToNullableInt32(SqlMoney p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4734 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4735 public static Int32? ToNullableInt32(SqlSingle p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4736 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4737 public static Int32? ToNullableInt32(SqlString p) { return p.IsNull ? (Int32?)null : ToInt32(p.Value); } | |
| 4738 | |
| 4739 #endif | |
| 4740 | |
| 4741 // From Object | |
| 4742 // | |
| 4743 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Int32?</c> value.</summary> | |
| 4744 public static Int32? ToNullableInt32(object p) | |
| 4745 { | |
| 4746 if (p == null) return null; | |
| 4747 | |
| 4748 if (p is Int32?) return (Int32?)p; | |
| 4749 | |
| 4750 var type = p.GetType(); | |
| 4751 | |
| 4752 // Primitive types | |
| 4753 // | |
| 4754 switch (Type.GetTypeCode(type)) | |
| 4755 { | |
| 4756 case TypeCode.DBNull : return null; | |
| 4757 case TypeCode.SByte : return ToNullableInt32((SByte) p); | |
| 4758 case TypeCode.Int16 : return ToNullableInt32((Int16) p); | |
| 4759 case TypeCode.Int32 : return ToNullableInt32((Int32) p); | |
| 4760 case TypeCode.Byte : return ToNullableInt32((Byte) p); | |
| 4761 case TypeCode.UInt16 : return ToNullableInt32((UInt16) p); | |
| 4762 case TypeCode.Char : return ToNullableInt32((Char) p); | |
| 4763 case TypeCode.Int64 : return ToNullableInt32((Int64) p); | |
| 4764 case TypeCode.UInt32 : return ToNullableInt32((UInt32) p); | |
| 4765 case TypeCode.UInt64 : return ToNullableInt32((UInt64) p); | |
| 4766 case TypeCode.Single : return ToNullableInt32((Single) p); | |
| 4767 case TypeCode.Double : return ToNullableInt32((Double) p); | |
| 4768 case TypeCode.Decimal : return ToNullableInt32((Decimal)p); | |
| 4769 case TypeCode.String : return ToNullableInt32((String) p); | |
| 4770 case TypeCode.Boolean : return ToNullableInt32((Boolean)p); | |
| 4771 } | |
| 4772 | |
| 4773 // Nullable Types | |
| 4774 // | |
| 4775 if (type.IsGenericType) | |
| 4776 { | |
| 4777 if (p is Boolean?) return ToNullableInt32((Boolean?) p); | |
| 4778 if (p is Byte?) return ToNullableInt32((Byte?) p); | |
| 4779 if (p is Char?) return ToNullableInt32((Char?) p); | |
| 4780 if (p is Decimal?) return ToNullableInt32((Decimal?) p); | |
| 4781 if (p is Double?) return ToNullableInt32((Double?) p); | |
| 4782 if (p is Int16?) return ToNullableInt32((Int16?) p); | |
| 4783 if (p is Int64?) return ToNullableInt32((Int64?) p); | |
| 4784 if (p is SByte?) return ToNullableInt32((SByte?) p); | |
| 4785 if (p is Single?) return ToNullableInt32((Single?) p); | |
| 4786 if (p is UInt16?) return ToNullableInt32((UInt16?) p); | |
| 4787 if (p is UInt32?) return ToNullableInt32((UInt32?) p); | |
| 4788 if (p is UInt64?) return ToNullableInt32((UInt64?) p); | |
| 4789 } | |
| 4790 | |
| 4791 // Other Types | |
| 4792 // | |
| 4793 if (p is Binary) return ToNullableInt32((Binary) p); | |
| 4794 if (p is Byte[]) return ToNullableInt32((Byte[]) p); | |
| 4795 | |
| 4796 #if !SILVERLIGHT | |
| 4797 | |
| 4798 // Sql Types | |
| 4799 // | |
| 4800 if (p is INullable) | |
| 4801 { | |
| 4802 if (p is SqlBoolean) return ToNullableInt32((SqlBoolean)p); | |
| 4803 if (p is SqlByte) return ToNullableInt32((SqlByte) p); | |
| 4804 if (p is SqlDecimal) return ToNullableInt32((SqlDecimal)p); | |
| 4805 if (p is SqlDouble) return ToNullableInt32((SqlDouble) p); | |
| 4806 if (p is SqlInt16) return ToNullableInt32((SqlInt16) p); | |
| 4807 if (p is SqlInt32) return ToNullableInt32((SqlInt32) p); | |
| 4808 if (p is SqlInt64) return ToNullableInt32((SqlInt64) p); | |
| 4809 if (p is SqlMoney) return ToNullableInt32((SqlMoney) p); | |
| 4810 if (p is SqlSingle) return ToNullableInt32((SqlSingle) p); | |
| 4811 if (p is SqlString) return ToNullableInt32((SqlString) p); | |
| 4812 } | |
| 4813 | |
| 4814 #endif | |
| 4815 | |
| 4816 throw CreateInvalidCastException(p.GetType(), typeof(Int32?)); | |
| 4817 } | |
| 4818 | |
| 4819 #endregion | |
| 4820 | |
| 4821 #region Int64? | |
| 4822 | |
| 4823 // Simple Types | |
| 4824 // | |
| 4825 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4826 public static Int64? ToNullableInt64(Boolean p) { return p ? (Int64?)1 : (Int64?)0; } | |
| 4827 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4828 public static Int64? ToNullableInt64(Byte p) { return p; } | |
| 4829 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4830 public static Int64? ToNullableInt64(Char p) { return p; } | |
| 4831 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4832 public static Int64? ToNullableInt64(DateTime p) { return (p - DateTime.MinValue).Ticks; } | |
| 4833 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4834 public static Int64? ToNullableInt64(DateTimeOffset p) { return (p - DateTime.MinValue).Ticks; } | |
| 4835 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4836 public static Int64? ToNullableInt64(Decimal p) { return checked((Int64?)p); } | |
| 4837 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4838 public static Int64? ToNullableInt64(Double p) { return checked((Int64?)p); } | |
| 4839 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4840 public static Int64? ToNullableInt64(Int16 p) { return p; } | |
| 4841 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4842 public static Int64? ToNullableInt64(Int32 p) { return p; } | |
| 4843 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4844 public static Int64? ToNullableInt64(Int64 p) { return p; } | |
| 4845 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4846 [CLSCompliant(false)] | |
| 4847 public static Int64? ToNullableInt64(SByte p) { return p; } | |
| 4848 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4849 public static Int64? ToNullableInt64(Single p) { return checked((Int64?)p); } | |
| 4850 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4851 public static Int64? ToNullableInt64(String p) { return p == null? (Int64?)null : Int64.Parse(p); } | |
| 4852 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4853 public static Int64? ToNullableInt64(TimeSpan p) { return p.Ticks; } | |
| 4854 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4855 [CLSCompliant(false)] | |
| 4856 public static Int64? ToNullableInt64(UInt16 p) { return p; } | |
| 4857 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4858 [CLSCompliant(false)] | |
| 4859 public static Int64? ToNullableInt64(UInt32 p) { return p; } | |
| 4860 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4861 [CLSCompliant(false)] | |
| 4862 public static Int64? ToNullableInt64(UInt64 p) { return checked((Int64?)p); } | |
| 4863 | |
| 4864 // Nullable Types | |
| 4865 // | |
| 4866 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4867 public static Int64? ToNullableInt64(Boolean? p) { return p.HasValue && p.Value ? (Int64?)1: (Int64?)0; } | |
| 4868 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4869 public static Int64? ToNullableInt64(Byte? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4870 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4871 public static Int64? ToNullableInt64(Char? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4872 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4873 public static Int64? ToNullableInt64(DateTime? p) { return p.HasValue ? (p.Value - DateTime.MinValue).Ticks : 0; } | |
| 4874 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4875 public static Int64? ToNullableInt64(DateTimeOffset? p) { return p.HasValue ? (p.Value - DateTime.MinValue).Ticks : 0; } | |
| 4876 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4877 public static Int64? ToNullableInt64(Decimal? p) { return p.HasValue ? checked((Int64?)p.Value) : (Int64?)null; } | |
| 4878 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4879 public static Int64? ToNullableInt64(Double? p) { return p.HasValue ? checked((Int64?)p.Value) : (Int64?)null; } | |
| 4880 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4881 public static Int64? ToNullableInt64(Int16? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4882 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4883 public static Int64? ToNullableInt64(Int32? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4884 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4885 [CLSCompliant(false)] | |
| 4886 public static Int64? ToNullableInt64(SByte? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4887 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4888 public static Int64? ToNullableInt64(Single? p) { return p.HasValue ? checked((Int64?)p.Value) : (Int64?)null; } | |
| 4889 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4890 public static Int64? ToNullableInt64(TimeSpan? p) { return p.HasValue ? p.Value.Ticks : 0; } | |
| 4891 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4892 [CLSCompliant(false)] | |
| 4893 public static Int64? ToNullableInt64(UInt16? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4894 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4895 [CLSCompliant(false)] | |
| 4896 public static Int64? ToNullableInt64(UInt32? p) { return p.HasValue ? p.Value : (Int64?)null; } | |
| 4897 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4898 [CLSCompliant(false)] | |
| 4899 public static Int64? ToNullableInt64(UInt64? p) { return p.HasValue ? checked((Int64?)p.Value) : (Int64?)null; } | |
| 4900 | |
| 4901 // Other Types | |
| 4902 // | |
| 4903 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4904 public static Int64? ToNullableInt64(Binary p) { return p == null || p.Length == 0 ? (Int64?)null : BitConverter.ToInt64(p.ToArray(), 0); } | |
| 4905 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4906 public static Int64? ToNullableInt64(Byte[] p) { return p == null || p.Length == 0 ? (Int64?)null : BitConverter.ToInt64(p, 0); } | |
| 4907 | |
| 4908 #if !SILVERLIGHT | |
| 4909 | |
| 4910 // Sql Types | |
| 4911 // | |
| 4912 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4913 public static Int64? ToNullableInt64(SqlBoolean p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4914 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4915 public static Int64? ToNullableInt64(SqlByte p) { return p.IsNull ? (Int64?)null : p.Value; } | |
| 4916 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4917 public static Int64? ToNullableInt64(SqlDateTime p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4918 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4919 public static Int64? ToNullableInt64(SqlDecimal p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4920 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4921 public static Int64? ToNullableInt64(SqlDouble p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4922 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4923 public static Int64? ToNullableInt64(SqlInt16 p) { return p.IsNull ? (Int64?)null : p.Value; } | |
| 4924 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4925 public static Int64? ToNullableInt64(SqlInt32 p) { return p.IsNull ? (Int64?)null : p.Value; } | |
| 4926 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4927 public static Int64? ToNullableInt64(SqlInt64 p) { return p.IsNull ? (Int64?)null : p.Value; } | |
| 4928 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4929 public static Int64? ToNullableInt64(SqlMoney p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4930 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4931 public static Int64? ToNullableInt64(SqlSingle p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4932 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4933 public static Int64? ToNullableInt64(SqlString p) { return p.IsNull ? (Int64?)null : ToInt64(p.Value); } | |
| 4934 | |
| 4935 #endif | |
| 4936 | |
| 4937 // From Object | |
| 4938 // | |
| 4939 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Int64?</c> value.</summary> | |
| 4940 public static Int64? ToNullableInt64(object p) | |
| 4941 { | |
| 4942 if (p == null) return null; | |
| 4943 | |
| 4944 if (p is Int64?) return (Int64?)p; | |
| 4945 | |
| 4946 var type = p.GetType(); | |
| 4947 | |
| 4948 // Primitive types | |
| 4949 // | |
| 4950 switch (Type.GetTypeCode(type)) | |
| 4951 { | |
| 4952 case TypeCode.DBNull : return null; | |
| 4953 case TypeCode.DateTime : return ToNullableInt64((DateTime)p); | |
| 4954 case TypeCode.SByte : return ToNullableInt64((SByte) p); | |
| 4955 case TypeCode.Int16 : return ToNullableInt64((Int16) p); | |
| 4956 case TypeCode.Int32 : return ToNullableInt64((Int32) p); | |
| 4957 case TypeCode.Int64 : return ToNullableInt64((Int64) p); | |
| 4958 case TypeCode.Byte : return ToNullableInt64((Byte) p); | |
| 4959 case TypeCode.UInt16 : return ToNullableInt64((UInt16) p); | |
| 4960 case TypeCode.UInt32 : return ToNullableInt64((UInt32) p); | |
| 4961 case TypeCode.Char : return ToNullableInt64((Char) p); | |
| 4962 case TypeCode.UInt64 : return ToNullableInt64((UInt64) p); | |
| 4963 case TypeCode.Single : return ToNullableInt64((Single) p); | |
| 4964 case TypeCode.Double : return ToNullableInt64((Double) p); | |
| 4965 case TypeCode.Decimal : return ToNullableInt64((Decimal) p); | |
| 4966 case TypeCode.String : return ToNullableInt64((String) p); | |
| 4967 case TypeCode.Boolean : return ToNullableInt64((Boolean) p); | |
| 4968 } | |
| 4969 | |
| 4970 // Simple Types | |
| 4971 // | |
| 4972 if (p is DateTimeOffset) return ToNullableInt64((DateTimeOffset) p); | |
| 4973 if (p is TimeSpan) return ToNullableInt64((TimeSpan) p); | |
| 4974 | |
| 4975 // Nullable Types | |
| 4976 // | |
| 4977 if (type.IsGenericType) | |
| 4978 { | |
| 4979 if (p is Boolean?) return ToNullableInt64((Boolean?) p); | |
| 4980 if (p is Byte?) return ToNullableInt64((Byte?) p); | |
| 4981 if (p is Char?) return ToNullableInt64((Char?) p); | |
| 4982 if (p is DateTime?) return ToNullableInt64((DateTime?) p); | |
| 4983 if (p is DateTimeOffset?) return ToNullableInt64((DateTimeOffset?)p); | |
| 4984 if (p is Decimal?) return ToNullableInt64((Decimal?) p); | |
| 4985 if (p is Double?) return ToNullableInt64((Double?) p); | |
| 4986 if (p is Int16?) return ToNullableInt64((Int16?) p); | |
| 4987 if (p is Int32?) return ToNullableInt64((Int32?) p); | |
| 4988 if (p is SByte?) return ToNullableInt64((SByte?) p); | |
| 4989 if (p is Single?) return ToNullableInt64((Single?) p); | |
| 4990 if (p is TimeSpan?) return ToNullableInt64((TimeSpan?) p); | |
| 4991 if (p is UInt16?) return ToNullableInt64((UInt16?) p); | |
| 4992 if (p is UInt32?) return ToNullableInt64((UInt32?) p); | |
| 4993 if (p is UInt64?) return ToNullableInt64((UInt64?) p); | |
| 4994 } | |
| 4995 | |
| 4996 // Other Types | |
| 4997 // | |
| 4998 if (p is Binary) return ToNullableInt64((Binary) p); | |
| 4999 if (p is Byte[]) return ToNullableInt64((Byte[]) p); | |
| 5000 | |
| 5001 #if !SILVERLIGHT | |
| 5002 | |
| 5003 // Sql Types | |
| 5004 // | |
| 5005 if (p is INullable) | |
| 5006 { | |
| 5007 if (p is SqlBoolean) return ToNullableInt64((SqlBoolean) p); | |
| 5008 if (p is SqlByte) return ToNullableInt64((SqlByte) p); | |
| 5009 if (p is SqlDateTime) return ToNullableInt64((SqlDateTime) p); | |
| 5010 if (p is SqlDecimal) return ToNullableInt64((SqlDecimal) p); | |
| 5011 if (p is SqlDouble) return ToNullableInt64((SqlDouble) p); | |
| 5012 if (p is SqlInt16) return ToNullableInt64((SqlInt16) p); | |
| 5013 if (p is SqlInt32) return ToNullableInt64((SqlInt32) p); | |
| 5014 if (p is SqlInt64) return ToNullableInt64((SqlInt64) p); | |
| 5015 if (p is SqlMoney) return ToNullableInt64((SqlMoney) p); | |
| 5016 if (p is SqlSingle) return ToNullableInt64((SqlSingle) p); | |
| 5017 if (p is SqlString) return ToNullableInt64((SqlString) p); | |
| 5018 } | |
| 5019 | |
| 5020 #endif | |
| 5021 | |
| 5022 throw CreateInvalidCastException(p.GetType(), typeof(Int64?)); | |
| 5023 } | |
| 5024 | |
| 5025 #endregion | |
| 5026 | |
| 5027 #region SByte? | |
| 5028 | |
| 5029 // Simple Types | |
| 5030 // | |
| 5031 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5032 [CLSCompliant(false)] | |
| 5033 public static SByte? ToNullableSByte(Boolean p) { return p ? (SByte?)1 : (SByte?)0; } | |
| 5034 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5035 [CLSCompliant(false)] | |
| 5036 public static SByte? ToNullableSByte(Byte p) { return checked((SByte?)p); } | |
| 5037 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5038 [CLSCompliant(false)] | |
| 5039 public static SByte? ToNullableSByte(Char p) { return checked((SByte?)p); } | |
| 5040 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5041 [CLSCompliant(false)] | |
| 5042 public static SByte? ToNullableSByte(Decimal p) { return checked((SByte?)p); } | |
| 5043 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5044 [CLSCompliant(false)] | |
| 5045 public static SByte? ToNullableSByte(Double p) { return checked((SByte?)p); } | |
| 5046 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5047 [CLSCompliant(false)] | |
| 5048 public static SByte? ToNullableSByte(Int16 p) { return checked((SByte?)p); } | |
| 5049 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5050 [CLSCompliant(false)] | |
| 5051 public static SByte? ToNullableSByte(Int32 p) { return checked((SByte?)p); } | |
| 5052 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5053 [CLSCompliant(false)] | |
| 5054 public static SByte? ToNullableSByte(Int64 p) { return checked((SByte?)p); } | |
| 5055 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5056 [CLSCompliant(false)] | |
| 5057 public static SByte? ToNullableSByte(SByte p) { return p; } | |
| 5058 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5059 [CLSCompliant(false)] | |
| 5060 public static SByte? ToNullableSByte(Single p) { return checked((SByte?)p); } | |
| 5061 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5062 [CLSCompliant(false)] | |
| 5063 public static SByte? ToNullableSByte(String p) { return p == null? (SByte?)null : SByte.Parse(p); } | |
| 5064 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5065 [CLSCompliant(false)] | |
| 5066 public static SByte? ToNullableSByte(UInt16 p) { return checked((SByte?)p); } | |
| 5067 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5068 [CLSCompliant(false)] | |
| 5069 public static SByte? ToNullableSByte(UInt32 p) { return checked((SByte?)p); } | |
| 5070 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5071 [CLSCompliant(false)] | |
| 5072 public static SByte? ToNullableSByte(UInt64 p) { return checked((SByte?)p); } | |
| 5073 | |
| 5074 // Nullable Types | |
| 5075 // | |
| 5076 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5077 [CLSCompliant(false)] | |
| 5078 public static SByte? ToNullableSByte(Boolean? p) { return p.HasValue && p.Value ? (SByte?)1: (SByte?)0; } | |
| 5079 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5080 [CLSCompliant(false)] | |
| 5081 public static SByte? ToNullableSByte(Byte? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5082 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5083 [CLSCompliant(false)] | |
| 5084 public static SByte? ToNullableSByte(Char? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5085 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5086 [CLSCompliant(false)] | |
| 5087 public static SByte? ToNullableSByte(Decimal? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5088 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5089 [CLSCompliant(false)] | |
| 5090 public static SByte? ToNullableSByte(Double? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5091 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5092 [CLSCompliant(false)] | |
| 5093 public static SByte? ToNullableSByte(Int16? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5094 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5095 [CLSCompliant(false)] | |
| 5096 public static SByte? ToNullableSByte(Int32? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5097 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5098 [CLSCompliant(false)] | |
| 5099 public static SByte? ToNullableSByte(Int64? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5100 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5101 [CLSCompliant(false)] | |
| 5102 public static SByte? ToNullableSByte(Single? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5103 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5104 [CLSCompliant(false)] | |
| 5105 public static SByte? ToNullableSByte(UInt16? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5106 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5107 [CLSCompliant(false)] | |
| 5108 public static SByte? ToNullableSByte(UInt32? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5109 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5110 [CLSCompliant(false)] | |
| 5111 public static SByte? ToNullableSByte(UInt64? p) { return p.HasValue ? checked((SByte?)p.Value) : (SByte?)null; } | |
| 5112 | |
| 5113 // Other Types | |
| 5114 // | |
| 5115 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5116 [CLSCompliant(false)] | |
| 5117 public static SByte? ToNullableSByte(Binary p) { return p == null || p.Length == 0 ? (SByte?)null : checked((SByte?)p.ToArray()[0]); } | |
| 5118 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5119 [CLSCompliant(false)] | |
| 5120 public static SByte? ToNullableSByte(Byte[] p) { return p == null || p.Length == 0 ? (SByte?)null : checked((SByte?)p[0]); } | |
| 5121 | |
| 5122 #if !SILVERLIGHT | |
| 5123 | |
| 5124 // Sql Types | |
| 5125 // | |
| 5126 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5127 [CLSCompliant(false)] | |
| 5128 public static SByte? ToNullableSByte(SqlBoolean p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5129 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5130 [CLSCompliant(false)] | |
| 5131 public static SByte? ToNullableSByte(SqlByte p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5132 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5133 [CLSCompliant(false)] | |
| 5134 public static SByte? ToNullableSByte(SqlDecimal p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5135 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5136 [CLSCompliant(false)] | |
| 5137 public static SByte? ToNullableSByte(SqlDouble p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5138 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5139 [CLSCompliant(false)] | |
| 5140 public static SByte? ToNullableSByte(SqlInt16 p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5141 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5142 [CLSCompliant(false)] | |
| 5143 public static SByte? ToNullableSByte(SqlInt32 p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5144 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5145 [CLSCompliant(false)] | |
| 5146 public static SByte? ToNullableSByte(SqlInt64 p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5147 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5148 [CLSCompliant(false)] | |
| 5149 public static SByte? ToNullableSByte(SqlMoney p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5150 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5151 [CLSCompliant(false)] | |
| 5152 public static SByte? ToNullableSByte(SqlSingle p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5153 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5154 [CLSCompliant(false)] | |
| 5155 public static SByte? ToNullableSByte(SqlString p) { return p.IsNull ? (SByte?)null : ToSByte(p.Value); } | |
| 5156 | |
| 5157 #endif | |
| 5158 | |
| 5159 // From Object | |
| 5160 // | |
| 5161 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SByte?</c> value.</summary> | |
| 5162 [CLSCompliant(false)] | |
| 5163 public static SByte? ToNullableSByte(object p) | |
| 5164 { | |
| 5165 if (p == null) return null; | |
| 5166 | |
| 5167 if (p is SByte?) return (SByte?)p; | |
| 5168 | |
| 5169 var type = p.GetType(); | |
| 5170 | |
| 5171 // Primitive types | |
| 5172 // | |
| 5173 switch (Type.GetTypeCode(type)) | |
| 5174 { | |
| 5175 case TypeCode.DBNull : return null; | |
| 5176 case TypeCode.SByte : return ToNullableSByte((SByte) p); | |
| 5177 case TypeCode.Int16 : return ToNullableSByte((Int16) p); | |
| 5178 case TypeCode.Int32 : return ToNullableSByte((Int32) p); | |
| 5179 case TypeCode.Int64 : return ToNullableSByte((Int64) p); | |
| 5180 case TypeCode.Byte : return ToNullableSByte((Byte) p); | |
| 5181 case TypeCode.UInt16 : return ToNullableSByte((UInt16) p); | |
| 5182 case TypeCode.UInt32 : return ToNullableSByte((UInt32) p); | |
| 5183 case TypeCode.UInt64 : return ToNullableSByte((UInt64) p); | |
| 5184 case TypeCode.Single : return ToNullableSByte((Single) p); | |
| 5185 case TypeCode.Double : return ToNullableSByte((Double) p); | |
| 5186 case TypeCode.Decimal : return ToNullableSByte((Decimal)p); | |
| 5187 case TypeCode.Char : return ToNullableSByte((Char) p); | |
| 5188 case TypeCode.String : return ToNullableSByte((String) p); | |
| 5189 case TypeCode.Boolean : return ToNullableSByte((Boolean)p); | |
| 5190 } | |
| 5191 | |
| 5192 // Nullable Types | |
| 5193 // | |
| 5194 if (type.IsGenericType) | |
| 5195 { | |
| 5196 if (p is Boolean?) return ToNullableSByte((Boolean?) p); | |
| 5197 if (p is Byte?) return ToNullableSByte((Byte?) p); | |
| 5198 if (p is Char?) return ToNullableSByte((Char?) p); | |
| 5199 if (p is Decimal?) return ToNullableSByte((Decimal?) p); | |
| 5200 if (p is Double?) return ToNullableSByte((Double?) p); | |
| 5201 if (p is Int16?) return ToNullableSByte((Int16?) p); | |
| 5202 if (p is Int32?) return ToNullableSByte((Int32?) p); | |
| 5203 if (p is Int64?) return ToNullableSByte((Int64?) p); | |
| 5204 if (p is Single?) return ToNullableSByte((Single?) p); | |
| 5205 if (p is UInt16?) return ToNullableSByte((UInt16?) p); | |
| 5206 if (p is UInt32?) return ToNullableSByte((UInt32?) p); | |
| 5207 if (p is UInt64?) return ToNullableSByte((UInt64?) p); | |
| 5208 } | |
| 5209 | |
| 5210 // Other Types | |
| 5211 // | |
| 5212 if (p is Binary) return ToNullableSByte((Binary) p); | |
| 5213 if (p is Byte[]) return ToNullableSByte((Byte[]) p); | |
| 5214 | |
| 5215 #if !SILVERLIGHT | |
| 5216 | |
| 5217 // Sql Types | |
| 5218 // | |
| 5219 if (p is INullable) | |
| 5220 { | |
| 5221 if (p is SqlBoolean) return ToNullableSByte((SqlBoolean)p); | |
| 5222 if (p is SqlByte) return ToNullableSByte((SqlByte) p); | |
| 5223 if (p is SqlDecimal) return ToNullableSByte((SqlDecimal)p); | |
| 5224 if (p is SqlDouble) return ToNullableSByte((SqlDouble) p); | |
| 5225 if (p is SqlInt16) return ToNullableSByte((SqlInt16) p); | |
| 5226 if (p is SqlInt32) return ToNullableSByte((SqlInt32) p); | |
| 5227 if (p is SqlInt64) return ToNullableSByte((SqlInt64) p); | |
| 5228 if (p is SqlMoney) return ToNullableSByte((SqlMoney) p); | |
| 5229 if (p is SqlSingle) return ToNullableSByte((SqlSingle) p); | |
| 5230 if (p is SqlString) return ToNullableSByte((SqlString) p); | |
| 5231 } | |
| 5232 | |
| 5233 #endif | |
| 5234 | |
| 5235 throw CreateInvalidCastException(p.GetType(), typeof(SByte?)); | |
| 5236 } | |
| 5237 | |
| 5238 #endregion | |
| 5239 | |
| 5240 #region Single? | |
| 5241 | |
| 5242 // Simple Types | |
| 5243 // | |
| 5244 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5245 public static Single? ToNullableSingle(Boolean p) { return p ? (Single?)1 : (Single?)0; } | |
| 5246 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5247 public static Single? ToNullableSingle(Byte p) { return p; } | |
| 5248 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5249 public static Single? ToNullableSingle(Char p) { return p; } | |
| 5250 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5251 public static Single? ToNullableSingle(Decimal p) { return checked((Single?)p); } | |
| 5252 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5253 public static Single? ToNullableSingle(Double p) { return checked((Single?)p); } | |
| 5254 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5255 public static Single? ToNullableSingle(Int16 p) { return p; } | |
| 5256 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5257 public static Single? ToNullableSingle(Int32 p) { return p; } | |
| 5258 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5259 public static Single? ToNullableSingle(Int64 p) { return p; } | |
| 5260 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5261 [CLSCompliant(false)] | |
| 5262 public static Single? ToNullableSingle(SByte p) { return p; } | |
| 5263 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5264 public static Single? ToNullableSingle(Single p) { return p; } | |
| 5265 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5266 public static Single? ToNullableSingle(String p) { return p == null? (Single?)null : Single.Parse(p); } | |
| 5267 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5268 [CLSCompliant(false)] | |
| 5269 public static Single? ToNullableSingle(UInt16 p) { return p; } | |
| 5270 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5271 [CLSCompliant(false)] | |
| 5272 public static Single? ToNullableSingle(UInt32 p) { return p; } | |
| 5273 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5274 [CLSCompliant(false)] | |
| 5275 public static Single? ToNullableSingle(UInt64 p) { return p; } | |
| 5276 | |
| 5277 // Nullable Types | |
| 5278 // | |
| 5279 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5280 public static Single? ToNullableSingle(Boolean? p) { return p.HasValue && p.Value ? (Single?)1: (Single?)0; } | |
| 5281 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5282 public static Single? ToNullableSingle(Byte? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5283 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5284 public static Single? ToNullableSingle(Char? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5285 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5286 public static Single? ToNullableSingle(Decimal? p) { return p.HasValue ? checked((Single?)p.Value) : (Single?)null; } | |
| 5287 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5288 public static Single? ToNullableSingle(Double? p) { return p.HasValue ? checked((Single?)p.Value) : (Single?)null; } | |
| 5289 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5290 public static Single? ToNullableSingle(Int16? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5291 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5292 public static Single? ToNullableSingle(Int32? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5293 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5294 public static Single? ToNullableSingle(Int64? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5295 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5296 [CLSCompliant(false)] | |
| 5297 public static Single? ToNullableSingle(SByte? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5298 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5299 [CLSCompliant(false)] | |
| 5300 public static Single? ToNullableSingle(UInt16? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5301 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5302 [CLSCompliant(false)] | |
| 5303 public static Single? ToNullableSingle(UInt32? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5304 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5305 [CLSCompliant(false)] | |
| 5306 public static Single? ToNullableSingle(UInt64? p) { return p.HasValue ? p.Value : (Single?)null; } | |
| 5307 | |
| 5308 // Other Types | |
| 5309 // | |
| 5310 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5311 public static Single? ToNullableSingle(Binary p) { return p == null || p.Length == 0 ? (Single?)null : BitConverter.ToSingle(p.ToArray(), 0); } | |
| 5312 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5313 public static Single? ToNullableSingle(Byte[] p) { return p == null || p.Length == 0 ? (Single?)null : BitConverter.ToSingle(p, 0); } | |
| 5314 | |
| 5315 #if !SILVERLIGHT | |
| 5316 | |
| 5317 // Sql Types | |
| 5318 // | |
| 5319 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5320 public static Single? ToNullableSingle(SqlBoolean p) { return p.IsNull ? (Single?)null : ToSingle(p.Value); } | |
| 5321 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5322 public static Single? ToNullableSingle(SqlByte p) { return p.IsNull ? (Single?)null : p.Value; } | |
| 5323 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5324 public static Single? ToNullableSingle(SqlDecimal p) { return p.IsNull ? (Single?)null : ToSingle(p.Value); } | |
| 5325 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5326 public static Single? ToNullableSingle(SqlDouble p) { return p.IsNull ? (Single?)null : ToSingle(p.Value); } | |
| 5327 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5328 public static Single? ToNullableSingle(SqlInt16 p) { return p.IsNull ? (Single?)null : p.Value; } | |
| 5329 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5330 public static Single? ToNullableSingle(SqlInt32 p) { return p.IsNull ? (Single?)null : p.Value; } | |
| 5331 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5332 public static Single? ToNullableSingle(SqlInt64 p) { return p.IsNull ? (Single?)null : p.Value; } | |
| 5333 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5334 public static Single? ToNullableSingle(SqlMoney p) { return p.IsNull ? (Single?)null : ToSingle(p.Value); } | |
| 5335 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5336 public static Single? ToNullableSingle(SqlSingle p) { return p.IsNull ? (Single?)null : p.Value; } | |
| 5337 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5338 public static Single? ToNullableSingle(SqlString p) { return p.IsNull ? (Single?)null : ToSingle(p.Value); } | |
| 5339 | |
| 5340 #endif | |
| 5341 | |
| 5342 // From Object | |
| 5343 // | |
| 5344 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Single?</c> value.</summary> | |
| 5345 public static Single? ToNullableSingle(object p) | |
| 5346 { | |
| 5347 if (p == null) return null; | |
| 5348 | |
| 5349 if (p is Single?) return (Single?)p; | |
| 5350 | |
| 5351 var type = p.GetType(); | |
| 5352 | |
| 5353 // Primitive types | |
| 5354 // | |
| 5355 switch (Type.GetTypeCode(type)) | |
| 5356 { | |
| 5357 case TypeCode.DBNull : return null; | |
| 5358 case TypeCode.SByte : return ToNullableSingle((SByte) p); | |
| 5359 case TypeCode.Int16 : return ToNullableSingle((Int16) p); | |
| 5360 case TypeCode.Int32 : return ToNullableSingle((Int32) p); | |
| 5361 case TypeCode.Int64 : return ToNullableSingle((Int64) p); | |
| 5362 case TypeCode.Byte : return ToNullableSingle((Byte) p); | |
| 5363 case TypeCode.UInt16 : return ToNullableSingle((UInt16) p); | |
| 5364 case TypeCode.UInt32 : return ToNullableSingle((UInt32) p); | |
| 5365 case TypeCode.Char : return ToNullableSingle((Char) p); | |
| 5366 case TypeCode.UInt64 : return ToNullableSingle((UInt64) p); | |
| 5367 case TypeCode.Single : return ToNullableSingle((Single) p); | |
| 5368 case TypeCode.Double : return ToNullableSingle((Double) p); | |
| 5369 case TypeCode.Decimal : return ToNullableSingle((Decimal)p); | |
| 5370 case TypeCode.String : return ToNullableSingle((String) p); | |
| 5371 case TypeCode.Boolean : return ToNullableSingle((Boolean)p); | |
| 5372 } | |
| 5373 | |
| 5374 // Nullable Types | |
| 5375 // | |
| 5376 if (type.IsGenericType) | |
| 5377 { | |
| 5378 if (p is Boolean?) return ToNullableSingle((Boolean?) p); | |
| 5379 if (p is Byte?) return ToNullableSingle((Byte?) p); | |
| 5380 if (p is Char?) return ToNullableSingle((Char?) p); | |
| 5381 if (p is Decimal?) return ToNullableSingle((Decimal?) p); | |
| 5382 if (p is Double?) return ToNullableSingle((Double?) p); | |
| 5383 if (p is Int16?) return ToNullableSingle((Int16?) p); | |
| 5384 if (p is Int32?) return ToNullableSingle((Int32?) p); | |
| 5385 if (p is Int64?) return ToNullableSingle((Int64?) p); | |
| 5386 if (p is SByte?) return ToNullableSingle((SByte?) p); | |
| 5387 if (p is UInt16?) return ToNullableSingle((UInt16?) p); | |
| 5388 if (p is UInt32?) return ToNullableSingle((UInt32?) p); | |
| 5389 if (p is UInt64?) return ToNullableSingle((UInt64?) p); | |
| 5390 } | |
| 5391 | |
| 5392 // Other Types | |
| 5393 // | |
| 5394 if (p is Binary) return ToNullableSingle((Binary) p); | |
| 5395 if (p is Byte[]) return ToNullableSingle((Byte[]) p); | |
| 5396 | |
| 5397 #if !SILVERLIGHT | |
| 5398 | |
| 5399 // Sql Types | |
| 5400 // | |
| 5401 if (p is INullable) | |
| 5402 { | |
| 5403 if (p is SqlBoolean) return ToNullableSingle((SqlBoolean)p); | |
| 5404 if (p is SqlByte) return ToNullableSingle((SqlByte) p); | |
| 5405 if (p is SqlDecimal) return ToNullableSingle((SqlDecimal)p); | |
| 5406 if (p is SqlDouble) return ToNullableSingle((SqlDouble) p); | |
| 5407 if (p is SqlInt16) return ToNullableSingle((SqlInt16) p); | |
| 5408 if (p is SqlInt32) return ToNullableSingle((SqlInt32) p); | |
| 5409 if (p is SqlInt64) return ToNullableSingle((SqlInt64) p); | |
| 5410 if (p is SqlMoney) return ToNullableSingle((SqlMoney) p); | |
| 5411 if (p is SqlSingle) return ToNullableSingle((SqlSingle) p); | |
| 5412 if (p is SqlString) return ToNullableSingle((SqlString) p); | |
| 5413 } | |
| 5414 | |
| 5415 #endif | |
| 5416 | |
| 5417 throw CreateInvalidCastException(p.GetType(), typeof(Single?)); | |
| 5418 } | |
| 5419 | |
| 5420 #endregion | |
| 5421 | |
| 5422 #region TimeSpan? | |
| 5423 | |
| 5424 // Simple Types | |
| 5425 // | |
| 5426 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5427 public static TimeSpan? ToNullableTimeSpan(DateTime p) { return p - DateTime.MinValue; } | |
| 5428 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5429 public static TimeSpan? ToNullableTimeSpan(DateTimeOffset p) { return p - DateTimeOffset.MinValue; } | |
| 5430 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5431 public static TimeSpan? ToNullableTimeSpan(Double p) { return TimeSpan.FromDays (p); } | |
| 5432 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5433 public static TimeSpan? ToNullableTimeSpan(Int64 p) { return TimeSpan.FromTicks(p); } | |
| 5434 /// <summary>Converts the value from <c>String</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5435 public static TimeSpan? ToNullableTimeSpan(String p) { return p == null? (TimeSpan?)null : TimeSpan.Parse(p); } | |
| 5436 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5437 public static TimeSpan? ToNullableTimeSpan(TimeSpan p) { return p; } | |
| 5438 | |
| 5439 // Nullable Types | |
| 5440 // | |
| 5441 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5442 public static TimeSpan? ToNullableTimeSpan(DateTime? p) { return p.HasValue ? p.Value - DateTime.MinValue : (TimeSpan?)null; } | |
| 5443 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5444 public static TimeSpan? ToNullableTimeSpan(DateTimeOffset? p) { return p.HasValue ? p.Value - DateTimeOffset.MinValue : (TimeSpan?)null; } | |
| 5445 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5446 public static TimeSpan? ToNullableTimeSpan(Double? p) { return p.HasValue ? TimeSpan.FromDays (p.Value) : (TimeSpan?)null; } | |
| 5447 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5448 public static TimeSpan? ToNullableTimeSpan(Int64? p) { return p.HasValue ? TimeSpan.FromTicks(p.Value) : (TimeSpan?)null; } | |
| 5449 | |
| 5450 // Other Types | |
| 5451 // | |
| 5452 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5453 public static TimeSpan? ToNullableTimeSpan(Binary p) { return p == null || p.Length == 0? (TimeSpan?)null : TimeSpan.FromTicks(ToInt64(p.ToArray())); } | |
| 5454 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5455 public static TimeSpan? ToNullableTimeSpan(Byte[] p) { return p == null || p.Length == 0? (TimeSpan?)null : TimeSpan.FromTicks(ToInt64(p)); } | |
| 5456 | |
| 5457 #if !SILVERLIGHT | |
| 5458 | |
| 5459 // Sql Types | |
| 5460 // | |
| 5461 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5462 public static TimeSpan? ToNullableTimeSpan(SqlDateTime p) { return p.IsNull ? (TimeSpan?)null : p.Value - DateTime.MinValue; } | |
| 5463 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5464 public static TimeSpan? ToNullableTimeSpan(SqlDouble p) { return p.IsNull ? (TimeSpan?)null : TimeSpan.FromDays(p.Value); } | |
| 5465 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5466 public static TimeSpan? ToNullableTimeSpan(SqlInt64 p) { return p.IsNull ? (TimeSpan?)null : TimeSpan.FromTicks(p.Value); } | |
| 5467 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5468 public static TimeSpan? ToNullableTimeSpan(SqlString p) { return p.IsNull ? (TimeSpan?)null : TimeSpan.Parse(p.Value); } | |
| 5469 | |
| 5470 #endif | |
| 5471 | |
| 5472 // From Object | |
| 5473 // | |
| 5474 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>TimeSpan?</c> value.</summary> | |
| 5475 public static TimeSpan? ToNullableTimeSpan(object p) | |
| 5476 { | |
| 5477 if (p == null) return null; | |
| 5478 | |
| 5479 if (p is TimeSpan?) return (TimeSpan?)p; | |
| 5480 | |
| 5481 var type = p.GetType(); | |
| 5482 | |
| 5483 // Primitive types | |
| 5484 // | |
| 5485 switch (Type.GetTypeCode(type)) | |
| 5486 { | |
| 5487 case TypeCode.DBNull : return null; | |
| 5488 case TypeCode.DateTime : return ToNullableTimeSpan((DateTime) p); | |
| 5489 case TypeCode.Int64 : return ToNullableTimeSpan((Int64) p); | |
| 5490 case TypeCode.Double : return ToNullableTimeSpan((Double) p); | |
| 5491 case TypeCode.String : return ToNullableTimeSpan((String) p); | |
| 5492 } | |
| 5493 | |
| 5494 // Simple Types | |
| 5495 // | |
| 5496 if (p is DateTimeOffset) return ToNullableTimeSpan((DateTimeOffset) p); | |
| 5497 if (p is TimeSpan) return ToNullableTimeSpan((TimeSpan) p); | |
| 5498 | |
| 5499 // Nullable Types | |
| 5500 // | |
| 5501 if (type.IsGenericType) | |
| 5502 { | |
| 5503 if (p is DateTime?) return ToNullableTimeSpan((DateTime?) p); | |
| 5504 if (p is DateTimeOffset?) return ToNullableTimeSpan((DateTimeOffset?)p); | |
| 5505 if (p is Double?) return ToNullableTimeSpan((Double?) p); | |
| 5506 if (p is Int64?) return ToNullableTimeSpan((Int64?) p); | |
| 5507 } | |
| 5508 | |
| 5509 // Other Types | |
| 5510 // | |
| 5511 if (p is Binary) return ToNullableTimeSpan((Binary) p); | |
| 5512 if (p is Byte[]) return ToNullableTimeSpan((Byte[]) p); | |
| 5513 | |
| 5514 #if !SILVERLIGHT | |
| 5515 | |
| 5516 // Sql Types | |
| 5517 // | |
| 5518 if (p is INullable) | |
| 5519 { | |
| 5520 if (p is SqlDateTime) return ToNullableTimeSpan((SqlDateTime) p); | |
| 5521 if (p is SqlDouble) return ToNullableTimeSpan((SqlDouble) p); | |
| 5522 if (p is SqlInt64) return ToNullableTimeSpan((SqlInt64) p); | |
| 5523 if (p is SqlString) return ToNullableTimeSpan((SqlString) p); | |
| 5524 } | |
| 5525 | |
| 5526 #endif | |
| 5527 | |
| 5528 throw CreateInvalidCastException(p.GetType(), typeof(TimeSpan?)); | |
| 5529 } | |
| 5530 | |
| 5531 #endregion | |
| 5532 | |
| 5533 #region UInt16? | |
| 5534 | |
| 5535 // Simple Types | |
| 5536 // | |
| 5537 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5538 [CLSCompliant(false)] | |
| 5539 public static UInt16? ToNullableUInt16(Boolean p) { return p ? (UInt16?)1 : (UInt16?)0; } | |
| 5540 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5541 [CLSCompliant(false)] | |
| 5542 public static UInt16? ToNullableUInt16(Byte p) { return p; } | |
| 5543 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5544 [CLSCompliant(false)] | |
| 5545 public static UInt16? ToNullableUInt16(Char p) { return checked((UInt16?)p); } | |
| 5546 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5547 [CLSCompliant(false)] | |
| 5548 public static UInt16? ToNullableUInt16(Decimal p) { return checked((UInt16?)p); } | |
| 5549 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5550 [CLSCompliant(false)] | |
| 5551 public static UInt16? ToNullableUInt16(Double p) { return checked((UInt16?)p); } | |
| 5552 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5553 [CLSCompliant(false)] | |
| 5554 public static UInt16? ToNullableUInt16(Int16 p) { return checked((UInt16?)p); } | |
| 5555 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5556 [CLSCompliant(false)] | |
| 5557 public static UInt16? ToNullableUInt16(Int32 p) { return checked((UInt16?)p); } | |
| 5558 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5559 [CLSCompliant(false)] | |
| 5560 public static UInt16? ToNullableUInt16(Int64 p) { return checked((UInt16?)p); } | |
| 5561 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5562 [CLSCompliant(false)] | |
| 5563 public static UInt16? ToNullableUInt16(SByte p) { return checked((UInt16?)p); } | |
| 5564 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5565 [CLSCompliant(false)] | |
| 5566 public static UInt16? ToNullableUInt16(Single p) { return checked((UInt16?)p); } | |
| 5567 /// <summary>Converts the value from <c>String</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5568 [CLSCompliant(false)] | |
| 5569 public static UInt16? ToNullableUInt16(String p) { return p == null? (UInt16?)null : UInt16.Parse(p); } | |
| 5570 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5571 [CLSCompliant(false)] | |
| 5572 public static UInt16? ToNullableUInt16(UInt16 p) { return p; } | |
| 5573 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5574 [CLSCompliant(false)] | |
| 5575 public static UInt16? ToNullableUInt16(UInt32 p) { return checked((UInt16?)p); } | |
| 5576 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5577 [CLSCompliant(false)] | |
| 5578 public static UInt16? ToNullableUInt16(UInt64 p) { return checked((UInt16?)p); } | |
| 5579 | |
| 5580 // Nullable Types | |
| 5581 // | |
| 5582 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5583 [CLSCompliant(false)] | |
| 5584 public static UInt16? ToNullableUInt16(Boolean? p) { return p.HasValue && p.Value ? (UInt16?)1: (UInt16?)0; } | |
| 5585 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5586 [CLSCompliant(false)] | |
| 5587 public static UInt16? ToNullableUInt16(Byte? p) { return p.HasValue ? p.Value : (UInt16?)null; } | |
| 5588 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5589 [CLSCompliant(false)] | |
| 5590 public static UInt16? ToNullableUInt16(Char? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5591 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5592 [CLSCompliant(false)] | |
| 5593 public static UInt16? ToNullableUInt16(Decimal? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5594 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5595 [CLSCompliant(false)] | |
| 5596 public static UInt16? ToNullableUInt16(Double? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5597 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5598 [CLSCompliant(false)] | |
| 5599 public static UInt16? ToNullableUInt16(Int16? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5600 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5601 [CLSCompliant(false)] | |
| 5602 public static UInt16? ToNullableUInt16(Int32? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5603 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5604 [CLSCompliant(false)] | |
| 5605 public static UInt16? ToNullableUInt16(Int64? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5606 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5607 [CLSCompliant(false)] | |
| 5608 public static UInt16? ToNullableUInt16(SByte? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5609 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5610 [CLSCompliant(false)] | |
| 5611 public static UInt16? ToNullableUInt16(Single? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5612 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5613 [CLSCompliant(false)] | |
| 5614 public static UInt16? ToNullableUInt16(UInt32? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5615 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5616 [CLSCompliant(false)] | |
| 5617 public static UInt16? ToNullableUInt16(UInt64? p) { return p.HasValue ? checked((UInt16?)p.Value) : (UInt16?)null; } | |
| 5618 | |
| 5619 // Other Types | |
| 5620 // | |
| 5621 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5622 [CLSCompliant(false)] | |
| 5623 public static UInt16? ToNullableUInt16(Binary p) { return p == null || p.Length == 0 ? (UInt16?)null : BitConverter.ToUInt16(p.ToArray(), 0); } | |
| 5624 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5625 [CLSCompliant(false)] | |
| 5626 public static UInt16? ToNullableUInt16(Byte[] p) { return p == null || p.Length == 0 ? (UInt16?)null : BitConverter.ToUInt16(p, 0); } | |
| 5627 | |
| 5628 #if !SILVERLIGHT | |
| 5629 | |
| 5630 // Sql Types | |
| 5631 // | |
| 5632 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5633 [CLSCompliant(false)] | |
| 5634 public static UInt16? ToNullableUInt16(SqlBoolean p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5635 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5636 [CLSCompliant(false)] | |
| 5637 public static UInt16? ToNullableUInt16(SqlByte p) { return p.IsNull ? (UInt16?)null : p.Value; } | |
| 5638 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5639 [CLSCompliant(false)] | |
| 5640 public static UInt16? ToNullableUInt16(SqlDecimal p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5641 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5642 [CLSCompliant(false)] | |
| 5643 public static UInt16? ToNullableUInt16(SqlDouble p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5644 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5645 [CLSCompliant(false)] | |
| 5646 public static UInt16? ToNullableUInt16(SqlInt16 p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5647 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5648 [CLSCompliant(false)] | |
| 5649 public static UInt16? ToNullableUInt16(SqlInt32 p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5650 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5651 [CLSCompliant(false)] | |
| 5652 public static UInt16? ToNullableUInt16(SqlInt64 p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5653 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5654 [CLSCompliant(false)] | |
| 5655 public static UInt16? ToNullableUInt16(SqlMoney p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5656 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5657 [CLSCompliant(false)] | |
| 5658 public static UInt16? ToNullableUInt16(SqlSingle p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5659 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5660 [CLSCompliant(false)] | |
| 5661 public static UInt16? ToNullableUInt16(SqlString p) { return p.IsNull ? (UInt16?)null : ToUInt16(p.Value); } | |
| 5662 | |
| 5663 #endif | |
| 5664 | |
| 5665 // From Object | |
| 5666 // | |
| 5667 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>UInt16?</c> value.</summary> | |
| 5668 [CLSCompliant(false)] | |
| 5669 public static UInt16? ToNullableUInt16(object p) | |
| 5670 { | |
| 5671 if (p == null) return null; | |
| 5672 | |
| 5673 if (p is UInt16?) return (UInt16?)p; | |
| 5674 | |
| 5675 var type = p.GetType(); | |
| 5676 | |
| 5677 // Primitive types | |
| 5678 // | |
| 5679 switch (Type.GetTypeCode(type)) | |
| 5680 { | |
| 5681 case TypeCode.DBNull : return null; | |
| 5682 case TypeCode.UInt16 : return ToNullableUInt16((UInt16) p); | |
| 5683 case TypeCode.Byte : return ToNullableUInt16((Byte) p); | |
| 5684 case TypeCode.SByte : return ToNullableUInt16((SByte) p); | |
| 5685 case TypeCode.Int16 : return ToNullableUInt16((Int16) p); | |
| 5686 case TypeCode.Int32 : return ToNullableUInt16((Int32) p); | |
| 5687 case TypeCode.Int64 : return ToNullableUInt16((Int64) p); | |
| 5688 case TypeCode.UInt32 : return ToNullableUInt16((UInt32) p); | |
| 5689 case TypeCode.UInt64 : return ToNullableUInt16((UInt64) p); | |
| 5690 case TypeCode.Single : return ToNullableUInt16((Single) p); | |
| 5691 case TypeCode.Double : return ToNullableUInt16((Double) p); | |
| 5692 case TypeCode.Decimal : return ToNullableUInt16((Decimal)p); | |
| 5693 case TypeCode.Char : return ToNullableUInt16((Char) p); | |
| 5694 case TypeCode.String : return ToNullableUInt16((String) p); | |
| 5695 case TypeCode.Boolean : return ToNullableUInt16((Boolean)p); | |
| 5696 } | |
| 5697 | |
| 5698 // Nullable Types | |
| 5699 // | |
| 5700 if (type.IsGenericType) | |
| 5701 { | |
| 5702 if (p is Boolean?) return ToNullableUInt16((Boolean?) p); | |
| 5703 if (p is Byte?) return ToNullableUInt16((Byte?) p); | |
| 5704 if (p is Char?) return ToNullableUInt16((Char?) p); | |
| 5705 if (p is Decimal?) return ToNullableUInt16((Decimal?) p); | |
| 5706 if (p is Double?) return ToNullableUInt16((Double?) p); | |
| 5707 if (p is Int16?) return ToNullableUInt16((Int16?) p); | |
| 5708 if (p is Int32?) return ToNullableUInt16((Int32?) p); | |
| 5709 if (p is Int64?) return ToNullableUInt16((Int64?) p); | |
| 5710 if (p is SByte?) return ToNullableUInt16((SByte?) p); | |
| 5711 if (p is Single?) return ToNullableUInt16((Single?) p); | |
| 5712 if (p is UInt32?) return ToNullableUInt16((UInt32?) p); | |
| 5713 if (p is UInt64?) return ToNullableUInt16((UInt64?) p); | |
| 5714 } | |
| 5715 | |
| 5716 // Other Types | |
| 5717 // | |
| 5718 if (p is Binary) return ToNullableUInt16((Binary) p); | |
| 5719 if (p is Byte[]) return ToNullableUInt16((Byte[]) p); | |
| 5720 | |
| 5721 #if !SILVERLIGHT | |
| 5722 | |
| 5723 // Sql Types | |
| 5724 // | |
| 5725 if (p is INullable) | |
| 5726 { | |
| 5727 if (p is SqlBoolean) return ToNullableUInt16((SqlBoolean)p); | |
| 5728 if (p is SqlByte) return ToNullableUInt16((SqlByte) p); | |
| 5729 if (p is SqlDecimal) return ToNullableUInt16((SqlDecimal)p); | |
| 5730 if (p is SqlDouble) return ToNullableUInt16((SqlDouble) p); | |
| 5731 if (p is SqlInt16) return ToNullableUInt16((SqlInt16) p); | |
| 5732 if (p is SqlInt32) return ToNullableUInt16((SqlInt32) p); | |
| 5733 if (p is SqlInt64) return ToNullableUInt16((SqlInt64) p); | |
| 5734 if (p is SqlMoney) return ToNullableUInt16((SqlMoney) p); | |
| 5735 if (p is SqlSingle) return ToNullableUInt16((SqlSingle) p); | |
| 5736 if (p is SqlString) return ToNullableUInt16((SqlString) p); | |
| 5737 } | |
| 5738 | |
| 5739 #endif | |
| 5740 | |
| 5741 throw CreateInvalidCastException(p.GetType(), typeof(UInt16?)); | |
| 5742 } | |
| 5743 | |
| 5744 #endregion | |
| 5745 | |
| 5746 #region UInt32? | |
| 5747 | |
| 5748 // Simple Types | |
| 5749 // | |
| 5750 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5751 [CLSCompliant(false)] | |
| 5752 public static UInt32? ToNullableUInt32(Boolean p) { return p ? (UInt32?)1 : (UInt32?)0; } | |
| 5753 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5754 [CLSCompliant(false)] | |
| 5755 public static UInt32? ToNullableUInt32(Byte p) { return p; } | |
| 5756 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5757 [CLSCompliant(false)] | |
| 5758 public static UInt32? ToNullableUInt32(Char p) { return checked((UInt32?)p); } | |
| 5759 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5760 [CLSCompliant(false)] | |
| 5761 public static UInt32? ToNullableUInt32(Decimal p) { return checked((UInt32?)p); } | |
| 5762 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5763 [CLSCompliant(false)] | |
| 5764 public static UInt32? ToNullableUInt32(Double p) { return checked((UInt32?)p); } | |
| 5765 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5766 [CLSCompliant(false)] | |
| 5767 public static UInt32? ToNullableUInt32(Int16 p) { return checked((UInt32?)p); } | |
| 5768 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5769 [CLSCompliant(false)] | |
| 5770 public static UInt32? ToNullableUInt32(Int32 p) { return checked((UInt32?)p); } | |
| 5771 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5772 [CLSCompliant(false)] | |
| 5773 public static UInt32? ToNullableUInt32(Int64 p) { return checked((UInt32?)p); } | |
| 5774 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5775 [CLSCompliant(false)] | |
| 5776 public static UInt32? ToNullableUInt32(SByte p) { return checked((UInt32?)p); } | |
| 5777 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5778 [CLSCompliant(false)] | |
| 5779 public static UInt32? ToNullableUInt32(Single p) { return checked((UInt32?)p); } | |
| 5780 /// <summary>Converts the value from <c>String</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5781 [CLSCompliant(false)] | |
| 5782 public static UInt32? ToNullableUInt32(String p) { return p == null? (UInt32?)null : UInt32.Parse(p); } | |
| 5783 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5784 [CLSCompliant(false)] | |
| 5785 public static UInt32? ToNullableUInt32(UInt16 p) { return p; } | |
| 5786 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5787 [CLSCompliant(false)] | |
| 5788 public static UInt32? ToNullableUInt32(UInt32 p) { return p; } | |
| 5789 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5790 [CLSCompliant(false)] | |
| 5791 public static UInt32? ToNullableUInt32(UInt64 p) { return checked((UInt32?)p); } | |
| 5792 | |
| 5793 // Nullable Types | |
| 5794 // | |
| 5795 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5796 [CLSCompliant(false)] | |
| 5797 public static UInt32? ToNullableUInt32(Boolean? p) { return p.HasValue && p.Value ? (UInt32?)1: (UInt32?)0; } | |
| 5798 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5799 [CLSCompliant(false)] | |
| 5800 public static UInt32? ToNullableUInt32(Byte? p) { return p.HasValue ? p.Value : (UInt32?)null; } | |
| 5801 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5802 [CLSCompliant(false)] | |
| 5803 public static UInt32? ToNullableUInt32(Char? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5804 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5805 [CLSCompliant(false)] | |
| 5806 public static UInt32? ToNullableUInt32(Decimal? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5807 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5808 [CLSCompliant(false)] | |
| 5809 public static UInt32? ToNullableUInt32(Double? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5810 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5811 [CLSCompliant(false)] | |
| 5812 public static UInt32? ToNullableUInt32(Int16? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5813 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5814 [CLSCompliant(false)] | |
| 5815 public static UInt32? ToNullableUInt32(Int32? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5816 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5817 [CLSCompliant(false)] | |
| 5818 public static UInt32? ToNullableUInt32(Int64? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5819 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5820 [CLSCompliant(false)] | |
| 5821 public static UInt32? ToNullableUInt32(SByte? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5822 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5823 [CLSCompliant(false)] | |
| 5824 public static UInt32? ToNullableUInt32(Single? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5825 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5826 [CLSCompliant(false)] | |
| 5827 public static UInt32? ToNullableUInt32(UInt16? p) { return p.HasValue ? p.Value : (UInt32?)null; } | |
| 5828 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5829 [CLSCompliant(false)] | |
| 5830 public static UInt32? ToNullableUInt32(UInt64? p) { return p.HasValue ? checked((UInt32?)p.Value) : (UInt32?)null; } | |
| 5831 | |
| 5832 // Other Types | |
| 5833 // | |
| 5834 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5835 [CLSCompliant(false)] | |
| 5836 public static UInt32? ToNullableUInt32(Binary p) { return p == null || p.Length == 0 ? (UInt32?)null : BitConverter.ToUInt32(p.ToArray(), 0); } | |
| 5837 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5838 [CLSCompliant(false)] | |
| 5839 public static UInt32? ToNullableUInt32(Byte[] p) { return p == null || p.Length == 0 ? (UInt32?)null : BitConverter.ToUInt32(p, 0); } | |
| 5840 | |
| 5841 #if !SILVERLIGHT | |
| 5842 | |
| 5843 // Sql Types | |
| 5844 // | |
| 5845 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5846 [CLSCompliant(false)] | |
| 5847 public static UInt32? ToNullableUInt32(SqlBoolean p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5848 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5849 [CLSCompliant(false)] | |
| 5850 public static UInt32? ToNullableUInt32(SqlByte p) { return p.IsNull ? (UInt32?)null : p.Value; } | |
| 5851 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5852 [CLSCompliant(false)] | |
| 5853 public static UInt32? ToNullableUInt32(SqlDecimal p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5854 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5855 [CLSCompliant(false)] | |
| 5856 public static UInt32? ToNullableUInt32(SqlDouble p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5857 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5858 [CLSCompliant(false)] | |
| 5859 public static UInt32? ToNullableUInt32(SqlInt16 p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5860 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5861 [CLSCompliant(false)] | |
| 5862 public static UInt32? ToNullableUInt32(SqlInt32 p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5863 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5864 [CLSCompliant(false)] | |
| 5865 public static UInt32? ToNullableUInt32(SqlInt64 p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5866 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5867 [CLSCompliant(false)] | |
| 5868 public static UInt32? ToNullableUInt32(SqlMoney p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5869 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5870 [CLSCompliant(false)] | |
| 5871 public static UInt32? ToNullableUInt32(SqlSingle p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5872 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5873 [CLSCompliant(false)] | |
| 5874 public static UInt32? ToNullableUInt32(SqlString p) { return p.IsNull ? (UInt32?)null : ToUInt32(p.Value); } | |
| 5875 | |
| 5876 #endif | |
| 5877 | |
| 5878 // From Object | |
| 5879 // | |
| 5880 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>UInt32?</c> value.</summary> | |
| 5881 [CLSCompliant(false)] | |
| 5882 public static UInt32? ToNullableUInt32(object p) | |
| 5883 { | |
| 5884 if (p == null) return null; | |
| 5885 | |
| 5886 if (p is UInt32?) return (UInt32?)p; | |
| 5887 | |
| 5888 var type = p.GetType(); | |
| 5889 | |
| 5890 // Primitive types | |
| 5891 // | |
| 5892 switch (Type.GetTypeCode(type)) | |
| 5893 { | |
| 5894 case TypeCode.DBNull : return null; | |
| 5895 case TypeCode.Byte : return ToNullableUInt32((Byte) p); | |
| 5896 case TypeCode.UInt16 : return ToNullableUInt32((UInt16) p); | |
| 5897 case TypeCode.UInt32 : return ToNullableUInt32((UInt32) p); | |
| 5898 case TypeCode.SByte : return ToNullableUInt32((SByte) p); | |
| 5899 case TypeCode.Int16 : return ToNullableUInt32((Int16) p); | |
| 5900 case TypeCode.Int32 : return ToNullableUInt32((Int32) p); | |
| 5901 case TypeCode.Int64 : return ToNullableUInt32((Int64) p); | |
| 5902 case TypeCode.UInt64 : return ToNullableUInt32((UInt64) p); | |
| 5903 case TypeCode.Single : return ToNullableUInt32((Single) p); | |
| 5904 case TypeCode.Double : return ToNullableUInt32((Double) p); | |
| 5905 case TypeCode.Decimal : return ToNullableUInt32((Decimal)p); | |
| 5906 case TypeCode.Char : return ToNullableUInt32((Char) p); | |
| 5907 case TypeCode.String : return ToNullableUInt32((String) p); | |
| 5908 case TypeCode.Boolean : return ToNullableUInt32((Boolean)p); | |
| 5909 } | |
| 5910 | |
| 5911 // Nullable Types | |
| 5912 // | |
| 5913 if (type.IsGenericType) | |
| 5914 { | |
| 5915 if (p is Boolean?) return ToNullableUInt32((Boolean?) p); | |
| 5916 if (p is Byte?) return ToNullableUInt32((Byte?) p); | |
| 5917 if (p is Char?) return ToNullableUInt32((Char?) p); | |
| 5918 if (p is Decimal?) return ToNullableUInt32((Decimal?) p); | |
| 5919 if (p is Double?) return ToNullableUInt32((Double?) p); | |
| 5920 if (p is Int16?) return ToNullableUInt32((Int16?) p); | |
| 5921 if (p is Int32?) return ToNullableUInt32((Int32?) p); | |
| 5922 if (p is Int64?) return ToNullableUInt32((Int64?) p); | |
| 5923 if (p is SByte?) return ToNullableUInt32((SByte?) p); | |
| 5924 if (p is Single?) return ToNullableUInt32((Single?) p); | |
| 5925 if (p is UInt16?) return ToNullableUInt32((UInt16?) p); | |
| 5926 if (p is UInt64?) return ToNullableUInt32((UInt64?) p); | |
| 5927 } | |
| 5928 | |
| 5929 // Other Types | |
| 5930 // | |
| 5931 if (p is Binary) return ToNullableUInt32((Binary) p); | |
| 5932 if (p is Byte[]) return ToNullableUInt32((Byte[]) p); | |
| 5933 | |
| 5934 #if !SILVERLIGHT | |
| 5935 | |
| 5936 // Sql Types | |
| 5937 // | |
| 5938 if (p is INullable) | |
| 5939 { | |
| 5940 if (p is SqlBoolean) return ToNullableUInt32((SqlBoolean)p); | |
| 5941 if (p is SqlByte) return ToNullableUInt32((SqlByte) p); | |
| 5942 if (p is SqlDecimal) return ToNullableUInt32((SqlDecimal)p); | |
| 5943 if (p is SqlDouble) return ToNullableUInt32((SqlDouble) p); | |
| 5944 if (p is SqlInt16) return ToNullableUInt32((SqlInt16) p); | |
| 5945 if (p is SqlInt32) return ToNullableUInt32((SqlInt32) p); | |
| 5946 if (p is SqlInt64) return ToNullableUInt32((SqlInt64) p); | |
| 5947 if (p is SqlMoney) return ToNullableUInt32((SqlMoney) p); | |
| 5948 if (p is SqlSingle) return ToNullableUInt32((SqlSingle) p); | |
| 5949 if (p is SqlString) return ToNullableUInt32((SqlString) p); | |
| 5950 } | |
| 5951 | |
| 5952 #endif | |
| 5953 | |
| 5954 throw CreateInvalidCastException(p.GetType(), typeof(UInt32?)); | |
| 5955 } | |
| 5956 | |
| 5957 #endregion | |
| 5958 | |
| 5959 #region UInt64? | |
| 5960 | |
| 5961 // Simple Types | |
| 5962 // | |
| 5963 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5964 [CLSCompliant(false)] | |
| 5965 public static UInt64? ToNullableUInt64(Boolean p) { return p ? (UInt64?)1 : (UInt64?)0; } | |
| 5966 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5967 [CLSCompliant(false)] | |
| 5968 public static UInt64? ToNullableUInt64(Byte p) { return p; } | |
| 5969 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5970 [CLSCompliant(false)] | |
| 5971 public static UInt64? ToNullableUInt64(Char p) { return checked((UInt64?)p); } | |
| 5972 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5973 [CLSCompliant(false)] | |
| 5974 public static UInt64? ToNullableUInt64(Decimal p) { return checked((UInt64?)p); } | |
| 5975 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5976 [CLSCompliant(false)] | |
| 5977 public static UInt64? ToNullableUInt64(Double p) { return checked((UInt64?)p); } | |
| 5978 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5979 [CLSCompliant(false)] | |
| 5980 public static UInt64? ToNullableUInt64(Int16 p) { return checked((UInt64?)p); } | |
| 5981 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5982 [CLSCompliant(false)] | |
| 5983 public static UInt64? ToNullableUInt64(Int32 p) { return checked((UInt64?)p); } | |
| 5984 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5985 [CLSCompliant(false)] | |
| 5986 public static UInt64? ToNullableUInt64(Int64 p) { return checked((UInt64?)p); } | |
| 5987 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5988 [CLSCompliant(false)] | |
| 5989 public static UInt64? ToNullableUInt64(SByte p) { return checked((UInt64?)p); } | |
| 5990 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5991 [CLSCompliant(false)] | |
| 5992 public static UInt64? ToNullableUInt64(Single p) { return checked((UInt64?)p); } | |
| 5993 /// <summary>Converts the value from <c>String</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5994 [CLSCompliant(false)] | |
| 5995 public static UInt64? ToNullableUInt64(String p) { return p == null? (UInt64?)null : UInt64.Parse(p); } | |
| 5996 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 5997 [CLSCompliant(false)] | |
| 5998 public static UInt64? ToNullableUInt64(UInt16 p) { return p; } | |
| 5999 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6000 [CLSCompliant(false)] | |
| 6001 public static UInt64? ToNullableUInt64(UInt32 p) { return p; } | |
| 6002 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6003 [CLSCompliant(false)] | |
| 6004 public static UInt64? ToNullableUInt64(UInt64 p) { return p; } | |
| 6005 | |
| 6006 // Nullable Types | |
| 6007 // | |
| 6008 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6009 [CLSCompliant(false)] | |
| 6010 public static UInt64? ToNullableUInt64(Boolean? p) { return p.HasValue && p.Value ? (UInt64?)1: (UInt64?)0; } | |
| 6011 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6012 [CLSCompliant(false)] | |
| 6013 public static UInt64? ToNullableUInt64(Byte? p) { return p.HasValue ? p.Value : (UInt64?)null; } | |
| 6014 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6015 [CLSCompliant(false)] | |
| 6016 public static UInt64? ToNullableUInt64(Char? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6017 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6018 [CLSCompliant(false)] | |
| 6019 public static UInt64? ToNullableUInt64(Decimal? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6020 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6021 [CLSCompliant(false)] | |
| 6022 public static UInt64? ToNullableUInt64(Double? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6023 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6024 [CLSCompliant(false)] | |
| 6025 public static UInt64? ToNullableUInt64(Int16? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6026 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6027 [CLSCompliant(false)] | |
| 6028 public static UInt64? ToNullableUInt64(Int32? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6029 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6030 [CLSCompliant(false)] | |
| 6031 public static UInt64? ToNullableUInt64(Int64? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6032 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6033 [CLSCompliant(false)] | |
| 6034 public static UInt64? ToNullableUInt64(SByte? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6035 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6036 [CLSCompliant(false)] | |
| 6037 public static UInt64? ToNullableUInt64(Single? p) { return p.HasValue ? checked((UInt64?)p.Value) : (UInt64?)null; } | |
| 6038 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6039 [CLSCompliant(false)] | |
| 6040 public static UInt64? ToNullableUInt64(UInt16? p) { return p.HasValue ? p.Value : (UInt64?)null; } | |
| 6041 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6042 [CLSCompliant(false)] | |
| 6043 public static UInt64? ToNullableUInt64(UInt32? p) { return p.HasValue ? p.Value : (UInt64?)null; } | |
| 6044 | |
| 6045 // Other Types | |
| 6046 // | |
| 6047 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6048 [CLSCompliant(false)] | |
| 6049 public static UInt64? ToNullableUInt64(Binary p) { return p == null || p.Length == 0 ? (UInt64?)null : BitConverter.ToUInt64(p.ToArray(), 0); } | |
| 6050 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6051 [CLSCompliant(false)] | |
| 6052 public static UInt64? ToNullableUInt64(Byte[] p) { return p == null || p.Length == 0 ? (UInt64?)null : BitConverter.ToUInt64(p, 0); } | |
| 6053 | |
| 6054 #if !SILVERLIGHT | |
| 6055 | |
| 6056 // Sql Types | |
| 6057 // | |
| 6058 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6059 [CLSCompliant(false)] | |
| 6060 public static UInt64? ToNullableUInt64(SqlBoolean p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6061 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6062 [CLSCompliant(false)] | |
| 6063 public static UInt64? ToNullableUInt64(SqlByte p) { return p.IsNull ? (UInt64?)null : p.Value; } | |
| 6064 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6065 [CLSCompliant(false)] | |
| 6066 public static UInt64? ToNullableUInt64(SqlDecimal p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6067 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6068 [CLSCompliant(false)] | |
| 6069 public static UInt64? ToNullableUInt64(SqlDouble p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6070 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6071 [CLSCompliant(false)] | |
| 6072 public static UInt64? ToNullableUInt64(SqlInt16 p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6073 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6074 [CLSCompliant(false)] | |
| 6075 public static UInt64? ToNullableUInt64(SqlInt32 p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6076 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6077 [CLSCompliant(false)] | |
| 6078 public static UInt64? ToNullableUInt64(SqlInt64 p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6079 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6080 [CLSCompliant(false)] | |
| 6081 public static UInt64? ToNullableUInt64(SqlMoney p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6082 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6083 [CLSCompliant(false)] | |
| 6084 public static UInt64? ToNullableUInt64(SqlSingle p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6085 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6086 [CLSCompliant(false)] | |
| 6087 public static UInt64? ToNullableUInt64(SqlString p) { return p.IsNull ? (UInt64?)null : ToUInt64(p.Value); } | |
| 6088 | |
| 6089 #endif | |
| 6090 | |
| 6091 // From Object | |
| 6092 // | |
| 6093 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>UInt64?</c> value.</summary> | |
| 6094 [CLSCompliant(false)] | |
| 6095 public static UInt64? ToNullableUInt64(object p) | |
| 6096 { | |
| 6097 if (p == null) return null; | |
| 6098 | |
| 6099 if (p is UInt64?) return (UInt64?)p; | |
| 6100 | |
| 6101 var type = p.GetType(); | |
| 6102 | |
| 6103 // Primitive types | |
| 6104 // | |
| 6105 switch (Type.GetTypeCode(type)) | |
| 6106 { | |
| 6107 case TypeCode.DBNull : return null; | |
| 6108 case TypeCode.Byte : return ToNullableUInt64((Byte) p); | |
| 6109 case TypeCode.UInt16 : return ToNullableUInt64((UInt16) p); | |
| 6110 case TypeCode.UInt32 : return ToNullableUInt64((UInt32) p); | |
| 6111 case TypeCode.UInt64 : return ToNullableUInt64((UInt64) p); | |
| 6112 case TypeCode.SByte : return ToNullableUInt64((SByte) p); | |
| 6113 case TypeCode.Int16 : return ToNullableUInt64((Int16) p); | |
| 6114 case TypeCode.Int32 : return ToNullableUInt64((Int32) p); | |
| 6115 case TypeCode.Int64 : return ToNullableUInt64((Int64) p); | |
| 6116 case TypeCode.Single : return ToNullableUInt64((Single) p); | |
| 6117 case TypeCode.Double : return ToNullableUInt64((Double) p); | |
| 6118 case TypeCode.Decimal : return ToNullableUInt64((Decimal)p); | |
| 6119 case TypeCode.Char : return ToNullableUInt64((Char) p); | |
| 6120 case TypeCode.String : return ToNullableUInt64((String) p); | |
| 6121 case TypeCode.Boolean : return ToNullableUInt64((Boolean)p); | |
| 6122 } | |
| 6123 | |
| 6124 // Nullable Types | |
| 6125 // | |
| 6126 if (type.IsGenericType) | |
| 6127 { | |
| 6128 if (p is Boolean?) return ToNullableUInt64((Boolean?) p); | |
| 6129 if (p is Byte?) return ToNullableUInt64((Byte?) p); | |
| 6130 if (p is Char?) return ToNullableUInt64((Char?) p); | |
| 6131 if (p is Decimal?) return ToNullableUInt64((Decimal?) p); | |
| 6132 if (p is Double?) return ToNullableUInt64((Double?) p); | |
| 6133 if (p is Int16?) return ToNullableUInt64((Int16?) p); | |
| 6134 if (p is Int32?) return ToNullableUInt64((Int32?) p); | |
| 6135 if (p is Int64?) return ToNullableUInt64((Int64?) p); | |
| 6136 if (p is SByte?) return ToNullableUInt64((SByte?) p); | |
| 6137 if (p is Single?) return ToNullableUInt64((Single?) p); | |
| 6138 if (p is UInt16?) return ToNullableUInt64((UInt16?) p); | |
| 6139 if (p is UInt32?) return ToNullableUInt64((UInt32?) p); | |
| 6140 } | |
| 6141 | |
| 6142 // Other Types | |
| 6143 // | |
| 6144 if (p is Binary) return ToNullableUInt64((Binary) p); | |
| 6145 if (p is Byte[]) return ToNullableUInt64((Byte[]) p); | |
| 6146 | |
| 6147 #if !SILVERLIGHT | |
| 6148 | |
| 6149 // Sql Types | |
| 6150 // | |
| 6151 if (p is INullable) | |
| 6152 { | |
| 6153 if (p is SqlBoolean) return ToNullableUInt64((SqlBoolean)p); | |
| 6154 if (p is SqlByte) return ToNullableUInt64((SqlByte) p); | |
| 6155 if (p is SqlDecimal) return ToNullableUInt64((SqlDecimal)p); | |
| 6156 if (p is SqlDouble) return ToNullableUInt64((SqlDouble) p); | |
| 6157 if (p is SqlInt16) return ToNullableUInt64((SqlInt16) p); | |
| 6158 if (p is SqlInt32) return ToNullableUInt64((SqlInt32) p); | |
| 6159 if (p is SqlInt64) return ToNullableUInt64((SqlInt64) p); | |
| 6160 if (p is SqlMoney) return ToNullableUInt64((SqlMoney) p); | |
| 6161 if (p is SqlSingle) return ToNullableUInt64((SqlSingle) p); | |
| 6162 if (p is SqlString) return ToNullableUInt64((SqlString) p); | |
| 6163 } | |
| 6164 | |
| 6165 #endif | |
| 6166 | |
| 6167 throw CreateInvalidCastException(p.GetType(), typeof(UInt64?)); | |
| 6168 } | |
| 6169 | |
| 6170 #endregion | |
| 6171 | |
| 6172 #endregion | |
| 6173 | |
| 6174 #region Sql Types | |
| 6175 | |
| 6176 #region SqlBinary | |
| 6177 | |
| 6178 #if !SILVERLIGHT | |
| 6179 | |
| 6180 // Simple Types | |
| 6181 // | |
| 6182 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6183 public static SqlBinary ToSqlBinary(Guid p) { return p == Guid.Empty? SqlBinary.Null : new SqlGuid(p).ToSqlBinary(); } | |
| 6184 | |
| 6185 // Nullable Types | |
| 6186 // | |
| 6187 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6188 public static SqlBinary ToSqlBinary(Guid? p) { return p.HasValue ? new SqlGuid(p.Value).ToSqlBinary(): SqlBinary.Null; } | |
| 6189 | |
| 6190 // Sql Types | |
| 6191 // | |
| 6192 /// <summary>Converts the value from <c>SqlBytes</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6193 public static SqlBinary ToSqlBinary(SqlBytes p) { return p.ToSqlBinary(); } | |
| 6194 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6195 public static SqlBinary ToSqlBinary(SqlGuid p) { return p.ToSqlBinary(); } | |
| 6196 | |
| 6197 // Other Types | |
| 6198 // | |
| 6199 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6200 public static SqlBinary ToSqlBinary(Binary p) { return p == null ? SqlBinary.Null : p.ToArray(); } | |
| 6201 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6202 public static SqlBinary ToSqlBinary(Byte[] p) { return p; } | |
| 6203 | |
| 6204 // From Object | |
| 6205 // | |
| 6206 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlBinary</c> value.</summary> | |
| 6207 public static SqlBinary ToSqlBinary(object p) | |
| 6208 { | |
| 6209 if (p == null || p is DBNull) return SqlBinary.Null; | |
| 6210 | |
| 6211 if (p is SqlBinary) return (SqlBinary)p; | |
| 6212 | |
| 6213 // Simple Types | |
| 6214 // | |
| 6215 if (p is Guid) return ToSqlBinary((Guid) p); | |
| 6216 | |
| 6217 // Nullable Types | |
| 6218 // | |
| 6219 var type = p.GetType(); | |
| 6220 | |
| 6221 if (type.IsGenericType) | |
| 6222 { | |
| 6223 if (p is Guid?) return ToSqlBinary((Guid?) p); | |
| 6224 } | |
| 6225 | |
| 6226 // Sql Types | |
| 6227 // | |
| 6228 if (p is INullable) | |
| 6229 { | |
| 6230 if (p is SqlBytes) return ToSqlBinary((SqlBytes)p); | |
| 6231 if (p is SqlGuid) return ToSqlBinary((SqlGuid) p); | |
| 6232 } | |
| 6233 | |
| 6234 // Other Types | |
| 6235 // | |
| 6236 if (p is Binary) return ToSqlBinary((Binary) p); | |
| 6237 if (p is Byte[]) return ToSqlBinary((Byte[]) p); | |
| 6238 | |
| 6239 throw CreateInvalidCastException(p.GetType(), typeof(SqlBinary)); | |
| 6240 } | |
| 6241 | |
| 6242 #endif | |
| 6243 | |
| 6244 #endregion | |
| 6245 | |
| 6246 #region SqlBoolean | |
| 6247 | |
| 6248 #if !SILVERLIGHT | |
| 6249 | |
| 6250 // Simple Types | |
| 6251 // | |
| 6252 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6253 public static SqlBoolean ToSqlBoolean(Boolean p) { return p; } | |
| 6254 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6255 public static SqlBoolean ToSqlBoolean(Byte p) { return p != 0; } | |
| 6256 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6257 public static SqlBoolean ToSqlBoolean(Char p) { return ToBoolean(p); } | |
| 6258 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6259 public static SqlBoolean ToSqlBoolean(Decimal p) { return p != 0; } | |
| 6260 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6261 public static SqlBoolean ToSqlBoolean(Double p) { return p != 0; } | |
| 6262 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6263 public static SqlBoolean ToSqlBoolean(Int16 p) { return p != 0; } | |
| 6264 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6265 public static SqlBoolean ToSqlBoolean(Int32 p) { return p != 0; } | |
| 6266 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6267 public static SqlBoolean ToSqlBoolean(Int64 p) { return p != 0; } | |
| 6268 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6269 [CLSCompliant(false)] | |
| 6270 public static SqlBoolean ToSqlBoolean(SByte p) { return p != 0; } | |
| 6271 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6272 public static SqlBoolean ToSqlBoolean(Single p) { return p != 0; } | |
| 6273 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6274 public static SqlBoolean ToSqlBoolean(String p) { return p == null? SqlBoolean.Null : p.Length == 1 ? ToBoolean(p[0]) : Boolean.Parse(p); } | |
| 6275 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6276 [CLSCompliant(false)] | |
| 6277 public static SqlBoolean ToSqlBoolean(UInt16 p) { return p != 0; } | |
| 6278 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6279 [CLSCompliant(false)] | |
| 6280 public static SqlBoolean ToSqlBoolean(UInt32 p) { return p != 0; } | |
| 6281 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6282 [CLSCompliant(false)] | |
| 6283 public static SqlBoolean ToSqlBoolean(UInt64 p) { return p != 0; } | |
| 6284 | |
| 6285 // Nullable Types | |
| 6286 // | |
| 6287 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6288 public static SqlBoolean ToSqlBoolean(Boolean? p) { return p.HasValue ? p.Value : SqlBoolean.Null; } | |
| 6289 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6290 public static SqlBoolean ToSqlBoolean(Byte? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6291 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6292 public static SqlBoolean ToSqlBoolean(Char? p) { return p.HasValue && ToBoolean(p.Value); } | |
| 6293 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6294 public static SqlBoolean ToSqlBoolean(Decimal? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6295 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6296 public static SqlBoolean ToSqlBoolean(Double? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6297 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6298 public static SqlBoolean ToSqlBoolean(Int16? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6299 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6300 public static SqlBoolean ToSqlBoolean(Int32? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6301 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6302 public static SqlBoolean ToSqlBoolean(Int64? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6303 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6304 [CLSCompliant(false)] | |
| 6305 public static SqlBoolean ToSqlBoolean(SByte? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6306 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6307 public static SqlBoolean ToSqlBoolean(Single? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6308 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6309 [CLSCompliant(false)] | |
| 6310 public static SqlBoolean ToSqlBoolean(UInt16? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6311 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6312 [CLSCompliant(false)] | |
| 6313 public static SqlBoolean ToSqlBoolean(UInt32? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6314 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6315 [CLSCompliant(false)] | |
| 6316 public static SqlBoolean ToSqlBoolean(UInt64? p) { return p.HasValue ? p.Value != 0 : SqlBoolean.Null; } | |
| 6317 | |
| 6318 // Sql Types | |
| 6319 // | |
| 6320 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6321 public static SqlBoolean ToSqlBoolean(SqlByte p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6322 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6323 public static SqlBoolean ToSqlBoolean(SqlDecimal p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6324 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6325 public static SqlBoolean ToSqlBoolean(SqlDouble p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6326 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6327 public static SqlBoolean ToSqlBoolean(SqlInt16 p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6328 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6329 public static SqlBoolean ToSqlBoolean(SqlInt32 p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6330 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6331 public static SqlBoolean ToSqlBoolean(SqlInt64 p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6332 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6333 public static SqlBoolean ToSqlBoolean(SqlMoney p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6334 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6335 public static SqlBoolean ToSqlBoolean(SqlSingle p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6336 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6337 public static SqlBoolean ToSqlBoolean(SqlString p) { return p.IsNull ? SqlBoolean.Null : ToBoolean(p.Value); } | |
| 6338 | |
| 6339 // Other Types | |
| 6340 // | |
| 6341 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6342 public static SqlBoolean ToSqlBoolean(Binary p) { return p == null || p.Length == 0 ? SqlBoolean.Null : BitConverter.ToBoolean(p.ToArray(), 0); } | |
| 6343 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6344 public static SqlBoolean ToSqlBoolean(Byte[] p) { return p == null || p.Length == 0 ? SqlBoolean.Null : BitConverter.ToBoolean(p, 0); } | |
| 6345 | |
| 6346 // From Object | |
| 6347 // | |
| 6348 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlBoolean</c> value.</summary> | |
| 6349 public static SqlBoolean ToSqlBoolean(object p) | |
| 6350 { | |
| 6351 if (p == null) return SqlBoolean.Null; | |
| 6352 | |
| 6353 if (p is SqlBoolean) return (SqlBoolean)p; | |
| 6354 | |
| 6355 var type = p.GetType(); | |
| 6356 | |
| 6357 // Primitive types | |
| 6358 // | |
| 6359 switch (Type.GetTypeCode(type)) | |
| 6360 { | |
| 6361 case TypeCode.DBNull : return SqlBoolean.Null; | |
| 6362 case TypeCode.String : return ToSqlBoolean((String) p); | |
| 6363 case TypeCode.Boolean : return ToSqlBoolean((Boolean) p); | |
| 6364 case TypeCode.Char : return ToSqlBoolean((Char) p); | |
| 6365 case TypeCode.SByte : return ToSqlBoolean((SByte) p); | |
| 6366 case TypeCode.Int16 : return ToSqlBoolean((Int16) p); | |
| 6367 case TypeCode.Int32 : return ToSqlBoolean((Int32) p); | |
| 6368 case TypeCode.Int64 : return ToSqlBoolean((Int64) p); | |
| 6369 case TypeCode.Byte : return ToSqlBoolean((Byte) p); | |
| 6370 case TypeCode.UInt16 : return ToSqlBoolean((UInt16) p); | |
| 6371 case TypeCode.UInt32 : return ToSqlBoolean((UInt32) p); | |
| 6372 case TypeCode.UInt64 : return ToSqlBoolean((UInt64) p); | |
| 6373 case TypeCode.Single : return ToSqlBoolean((Single) p); | |
| 6374 case TypeCode.Double : return ToSqlBoolean((Double) p); | |
| 6375 case TypeCode.Decimal : return ToSqlBoolean((Decimal) p); | |
| 6376 } | |
| 6377 | |
| 6378 // Nullable Types | |
| 6379 // | |
| 6380 if (type.IsGenericType) | |
| 6381 { | |
| 6382 if (p is Boolean?) return ToSqlBoolean((Boolean?) p); | |
| 6383 if (p is Byte?) return ToSqlBoolean((Byte?) p); | |
| 6384 if (p is Char?) return ToSqlBoolean((Char?) p); | |
| 6385 if (p is Decimal?) return ToSqlBoolean((Decimal?) p); | |
| 6386 if (p is Double?) return ToSqlBoolean((Double?) p); | |
| 6387 if (p is Int16?) return ToSqlBoolean((Int16?) p); | |
| 6388 if (p is Int32?) return ToSqlBoolean((Int32?) p); | |
| 6389 if (p is Int64?) return ToSqlBoolean((Int64?) p); | |
| 6390 if (p is SByte?) return ToSqlBoolean((SByte?) p); | |
| 6391 if (p is Single?) return ToSqlBoolean((Single?) p); | |
| 6392 if (p is UInt16?) return ToSqlBoolean((UInt16?) p); | |
| 6393 if (p is UInt32?) return ToSqlBoolean((UInt32?) p); | |
| 6394 if (p is UInt64?) return ToSqlBoolean((UInt64?) p); | |
| 6395 } | |
| 6396 | |
| 6397 // Sql Types | |
| 6398 // | |
| 6399 if (p is INullable) | |
| 6400 { | |
| 6401 if (p is SqlByte) return ToSqlBoolean((SqlByte) p); | |
| 6402 if (p is SqlDecimal) return ToSqlBoolean((SqlDecimal)p); | |
| 6403 if (p is SqlDouble) return ToSqlBoolean((SqlDouble) p); | |
| 6404 if (p is SqlInt16) return ToSqlBoolean((SqlInt16) p); | |
| 6405 if (p is SqlInt32) return ToSqlBoolean((SqlInt32) p); | |
| 6406 if (p is SqlInt64) return ToSqlBoolean((SqlInt64) p); | |
| 6407 if (p is SqlMoney) return ToSqlBoolean((SqlMoney) p); | |
| 6408 if (p is SqlSingle) return ToSqlBoolean((SqlSingle) p); | |
| 6409 if (p is SqlString) return ToSqlBoolean((SqlString) p); | |
| 6410 } | |
| 6411 | |
| 6412 // Other Types | |
| 6413 // | |
| 6414 if (p is Binary) return ToSqlBoolean((Binary) p); | |
| 6415 if (p is Byte[]) return ToSqlBoolean((Byte[]) p); | |
| 6416 | |
| 6417 throw CreateInvalidCastException(p.GetType(), typeof(SqlBoolean)); | |
| 6418 } | |
| 6419 | |
| 6420 #endif | |
| 6421 | |
| 6422 #endregion | |
| 6423 | |
| 6424 #region SqlByte | |
| 6425 | |
| 6426 #if !SILVERLIGHT | |
| 6427 | |
| 6428 // Simple Types | |
| 6429 // | |
| 6430 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6431 public static SqlByte ToSqlByte(Boolean p) { return p ? (SqlByte)1 : (SqlByte)0; } | |
| 6432 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6433 public static SqlByte ToSqlByte(Byte p) { return p; } | |
| 6434 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6435 public static SqlByte ToSqlByte(Char p) { return checked((Byte)p); } | |
| 6436 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6437 public static SqlByte ToSqlByte(Decimal p) { return checked((Byte)p); } | |
| 6438 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6439 public static SqlByte ToSqlByte(Double p) { return checked((Byte)p); } | |
| 6440 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6441 public static SqlByte ToSqlByte(Int16 p) { return checked((Byte)p); } | |
| 6442 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6443 public static SqlByte ToSqlByte(Int32 p) { return checked((Byte)p); } | |
| 6444 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6445 public static SqlByte ToSqlByte(Int64 p) { return checked((Byte)p); } | |
| 6446 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6447 [CLSCompliant(false)] | |
| 6448 public static SqlByte ToSqlByte(SByte p) { return checked((Byte)p); } | |
| 6449 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6450 public static SqlByte ToSqlByte(Single p) { return checked((Byte)p); } | |
| 6451 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6452 public static SqlByte ToSqlByte(String p) { return p == null? SqlByte.Null : Byte.Parse(p); } | |
| 6453 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6454 [CLSCompliant(false)] | |
| 6455 public static SqlByte ToSqlByte(UInt16 p) { return checked((Byte)p); } | |
| 6456 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6457 [CLSCompliant(false)] | |
| 6458 public static SqlByte ToSqlByte(UInt32 p) { return checked((Byte)p); } | |
| 6459 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6460 [CLSCompliant(false)] | |
| 6461 public static SqlByte ToSqlByte(UInt64 p) { return checked((Byte)p); } | |
| 6462 | |
| 6463 // Nullable Types | |
| 6464 // | |
| 6465 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6466 public static SqlByte ToSqlByte(Boolean? p) { return p.HasValue && p.Value ? (SqlByte)1: (SqlByte)0; } | |
| 6467 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6468 public static SqlByte ToSqlByte(Byte? p) { return p.HasValue ? p.Value : SqlByte.Null; } | |
| 6469 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6470 public static SqlByte ToSqlByte(Char? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6471 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6472 public static SqlByte ToSqlByte(Decimal? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6473 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6474 public static SqlByte ToSqlByte(Double? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6475 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6476 public static SqlByte ToSqlByte(Int16? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6477 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6478 public static SqlByte ToSqlByte(Int32? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6479 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6480 public static SqlByte ToSqlByte(Int64? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6481 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6482 [CLSCompliant(false)] | |
| 6483 public static SqlByte ToSqlByte(SByte? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6484 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6485 public static SqlByte ToSqlByte(Single? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6486 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6487 [CLSCompliant(false)] | |
| 6488 public static SqlByte ToSqlByte(UInt16? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6489 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6490 [CLSCompliant(false)] | |
| 6491 public static SqlByte ToSqlByte(UInt32? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6492 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6493 [CLSCompliant(false)] | |
| 6494 public static SqlByte ToSqlByte(UInt64? p) { return p.HasValue ? checked((Byte)p.Value) : SqlByte.Null; } | |
| 6495 | |
| 6496 // Sql Types | |
| 6497 // | |
| 6498 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6499 public static SqlByte ToSqlByte(SqlBoolean p) { return p.ToSqlByte(); } | |
| 6500 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6501 public static SqlByte ToSqlByte(SqlDecimal p) { return p.ToSqlByte(); } | |
| 6502 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6503 public static SqlByte ToSqlByte(SqlDouble p) { return p.ToSqlByte(); } | |
| 6504 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6505 public static SqlByte ToSqlByte(SqlInt16 p) { return p.ToSqlByte(); } | |
| 6506 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6507 public static SqlByte ToSqlByte(SqlInt32 p) { return p.ToSqlByte(); } | |
| 6508 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6509 public static SqlByte ToSqlByte(SqlInt64 p) { return p.ToSqlByte(); } | |
| 6510 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6511 public static SqlByte ToSqlByte(SqlMoney p) { return p.ToSqlByte(); } | |
| 6512 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6513 public static SqlByte ToSqlByte(SqlSingle p) { return p.ToSqlByte(); } | |
| 6514 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6515 public static SqlByte ToSqlByte(SqlString p) { return p.ToSqlByte(); } | |
| 6516 | |
| 6517 // Other Types | |
| 6518 // | |
| 6519 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6520 public static SqlByte ToSqlByte(Binary p) { return p == null || p.Length == 0 ? SqlByte.Null : p.ToArray()[0]; } | |
| 6521 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6522 public static SqlByte ToSqlByte(Byte[] p) { return p == null || p.Length == 0 ? SqlByte.Null : p[0]; } | |
| 6523 | |
| 6524 // From Object | |
| 6525 // | |
| 6526 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlByte</c> value.</summary> | |
| 6527 public static SqlByte ToSqlByte(object p) | |
| 6528 { | |
| 6529 if (p == null) return SqlByte.Null; | |
| 6530 | |
| 6531 if (p is SqlByte) return (SqlByte)p; | |
| 6532 | |
| 6533 var type = p.GetType(); | |
| 6534 | |
| 6535 // Primitive types | |
| 6536 // | |
| 6537 switch (Type.GetTypeCode(type)) | |
| 6538 { | |
| 6539 case TypeCode.DBNull : return SqlByte.Null; | |
| 6540 case TypeCode.Byte : return ToSqlByte((Byte) p); | |
| 6541 case TypeCode.SByte : return ToSqlByte((SByte) p); | |
| 6542 case TypeCode.Int16 : return ToSqlByte((Int16) p); | |
| 6543 case TypeCode.Int32 : return ToSqlByte((Int32) p); | |
| 6544 case TypeCode.Int64 : return ToSqlByte((Int64) p); | |
| 6545 case TypeCode.UInt16 : return ToSqlByte((UInt16) p); | |
| 6546 case TypeCode.UInt32 : return ToSqlByte((UInt32) p); | |
| 6547 case TypeCode.UInt64 : return ToSqlByte((UInt64) p); | |
| 6548 case TypeCode.Single : return ToSqlByte((Single) p); | |
| 6549 case TypeCode.Double : return ToSqlByte((Double) p); | |
| 6550 case TypeCode.Decimal : return ToSqlByte((Decimal)p); | |
| 6551 case TypeCode.Char : return ToSqlByte((Char) p); | |
| 6552 case TypeCode.String : return ToSqlByte((String) p); | |
| 6553 case TypeCode.Boolean : return ToSqlByte((Boolean)p); | |
| 6554 } | |
| 6555 | |
| 6556 // Nullable Types | |
| 6557 // | |
| 6558 if (type.IsGenericType) | |
| 6559 { | |
| 6560 if (p is Boolean?) return ToSqlByte((Boolean?) p); | |
| 6561 if (p is Byte?) return ToSqlByte((Byte?) p); | |
| 6562 if (p is Char?) return ToSqlByte((Char?) p); | |
| 6563 if (p is Decimal?) return ToSqlByte((Decimal?) p); | |
| 6564 if (p is Double?) return ToSqlByte((Double?) p); | |
| 6565 if (p is Int16?) return ToSqlByte((Int16?) p); | |
| 6566 if (p is Int32?) return ToSqlByte((Int32?) p); | |
| 6567 if (p is Int64?) return ToSqlByte((Int64?) p); | |
| 6568 if (p is SByte?) return ToSqlByte((SByte?) p); | |
| 6569 if (p is Single?) return ToSqlByte((Single?) p); | |
| 6570 if (p is UInt16?) return ToSqlByte((UInt16?) p); | |
| 6571 if (p is UInt32?) return ToSqlByte((UInt32?) p); | |
| 6572 if (p is UInt64?) return ToSqlByte((UInt64?) p); | |
| 6573 } | |
| 6574 | |
| 6575 // Sql Types | |
| 6576 // | |
| 6577 if (p is INullable) | |
| 6578 { | |
| 6579 if (p is SqlBoolean) return ToSqlByte((SqlBoolean)p); | |
| 6580 if (p is SqlDecimal) return ToSqlByte((SqlDecimal)p); | |
| 6581 if (p is SqlDouble) return ToSqlByte((SqlDouble) p); | |
| 6582 if (p is SqlInt16) return ToSqlByte((SqlInt16) p); | |
| 6583 if (p is SqlInt32) return ToSqlByte((SqlInt32) p); | |
| 6584 if (p is SqlInt64) return ToSqlByte((SqlInt64) p); | |
| 6585 if (p is SqlMoney) return ToSqlByte((SqlMoney) p); | |
| 6586 if (p is SqlSingle) return ToSqlByte((SqlSingle) p); | |
| 6587 if (p is SqlString) return ToSqlByte((SqlString) p); | |
| 6588 } | |
| 6589 | |
| 6590 // Other Types | |
| 6591 // | |
| 6592 if (p is Binary) return ToSqlByte((Binary) p); | |
| 6593 if (p is Byte[]) return ToSqlByte((Byte[]) p); | |
| 6594 | |
| 6595 throw CreateInvalidCastException(p.GetType(), typeof(SqlByte)); | |
| 6596 } | |
| 6597 | |
| 6598 #endif | |
| 6599 | |
| 6600 #endregion | |
| 6601 | |
| 6602 #region SqlBytes | |
| 6603 | |
| 6604 #if !SILVERLIGHT | |
| 6605 | |
| 6606 // Simple Types | |
| 6607 // | |
| 6608 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6609 public static SqlBytes ToSqlBytes(Boolean p) { return new SqlBytes(ToByteArray(p)); } | |
| 6610 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6611 public static SqlBytes ToSqlBytes(Byte p) { return new SqlBytes(ToByteArray(p)); } | |
| 6612 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6613 public static SqlBytes ToSqlBytes(Char p) { return new SqlBytes(ToByteArray(p)); } | |
| 6614 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6615 public static SqlBytes ToSqlBytes(DateTime p) { return new SqlBytes(ToByteArray(p)); } | |
| 6616 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6617 public static SqlBytes ToSqlBytes(DateTimeOffset p) { return new SqlBytes(ToByteArray(p)); } | |
| 6618 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6619 public static SqlBytes ToSqlBytes(Double p) { return new SqlBytes(ToByteArray(p)); } | |
| 6620 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6621 public static SqlBytes ToSqlBytes(Guid p) { return p == Guid.Empty ? SqlBytes.Null: new SqlBytes(p.ToByteArray()); } | |
| 6622 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6623 public static SqlBytes ToSqlBytes(Int16 p) { return new SqlBytes(ToByteArray(p)); } | |
| 6624 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6625 public static SqlBytes ToSqlBytes(Int32 p) { return new SqlBytes(ToByteArray(p)); } | |
| 6626 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6627 public static SqlBytes ToSqlBytes(Int64 p) { return new SqlBytes(ToByteArray(p)); } | |
| 6628 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6629 [CLSCompliant(false)] | |
| 6630 public static SqlBytes ToSqlBytes(SByte p) { return new SqlBytes(ToByteArray(p)); } | |
| 6631 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6632 public static SqlBytes ToSqlBytes(Single p) { return new SqlBytes(ToByteArray(p)); } | |
| 6633 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6634 public static SqlBytes ToSqlBytes(String p) { return p == null ? SqlBytes.Null : new SqlBytes(ToByteArray(p)); } | |
| 6635 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6636 public static SqlBytes ToSqlBytes(TimeSpan p) { return new SqlBytes(ToByteArray(p)); } | |
| 6637 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6638 [CLSCompliant(false)] | |
| 6639 public static SqlBytes ToSqlBytes(UInt16 p) { return new SqlBytes(ToByteArray(p)); } | |
| 6640 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6641 [CLSCompliant(false)] | |
| 6642 public static SqlBytes ToSqlBytes(UInt32 p) { return new SqlBytes(ToByteArray(p)); } | |
| 6643 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6644 [CLSCompliant(false)] | |
| 6645 public static SqlBytes ToSqlBytes(UInt64 p) { return new SqlBytes(ToByteArray(p)); } | |
| 6646 | |
| 6647 // Nullable Types | |
| 6648 // | |
| 6649 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6650 public static SqlBytes ToSqlBytes(Boolean? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6651 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6652 public static SqlBytes ToSqlBytes(Byte? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6653 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6654 public static SqlBytes ToSqlBytes(Char? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6655 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6656 public static SqlBytes ToSqlBytes(DateTime? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6657 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6658 public static SqlBytes ToSqlBytes(DateTimeOffset? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6659 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6660 public static SqlBytes ToSqlBytes(Decimal? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6661 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6662 public static SqlBytes ToSqlBytes(Double? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6663 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6664 public static SqlBytes ToSqlBytes(Guid? p) { return p.HasValue ? new SqlBytes(p.Value.ToByteArray()) : SqlBytes.Null; } | |
| 6665 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6666 public static SqlBytes ToSqlBytes(Int16? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6667 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6668 public static SqlBytes ToSqlBytes(Int32? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6669 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6670 public static SqlBytes ToSqlBytes(Int64? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6671 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6672 [CLSCompliant(false)] | |
| 6673 public static SqlBytes ToSqlBytes(SByte? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6674 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6675 public static SqlBytes ToSqlBytes(Single? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6676 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6677 public static SqlBytes ToSqlBytes(TimeSpan? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6678 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6679 [CLSCompliant(false)] | |
| 6680 public static SqlBytes ToSqlBytes(UInt16? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6681 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6682 [CLSCompliant(false)] | |
| 6683 public static SqlBytes ToSqlBytes(UInt32? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6684 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6685 [CLSCompliant(false)] | |
| 6686 public static SqlBytes ToSqlBytes(UInt64? p) { return p.HasValue ? ToSqlBytes(p.Value) : SqlBytes.Null; } | |
| 6687 | |
| 6688 // Sql Types | |
| 6689 // | |
| 6690 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6691 public static SqlBytes ToSqlBytes(SqlBinary p) { return p.IsNull ? SqlBytes.Null : new SqlBytes(p); } | |
| 6692 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6693 public static SqlBytes ToSqlBytes(SqlGuid p) { return p.IsNull ? SqlBytes.Null : new SqlBytes(p.ToByteArray()); } | |
| 6694 | |
| 6695 // Other Types | |
| 6696 // | |
| 6697 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6698 public static SqlBytes ToSqlBytes(Binary p) { return p == null ? SqlBytes.Null : new SqlBytes(p.ToArray()); } | |
| 6699 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6700 public static SqlBytes ToSqlBytes(Byte[] p) { return p == null ? SqlBytes.Null : new SqlBytes(p); } | |
| 6701 /// <summary>Converts the value from <c>Stream</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6702 public static SqlBytes ToSqlBytes(Stream p) { return p == null ? SqlBytes.Null : new SqlBytes(p); } | |
| 6703 | |
| 6704 // From Object | |
| 6705 // | |
| 6706 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlBytes</c> value.</summary> | |
| 6707 public static SqlBytes ToSqlBytes(object p) | |
| 6708 { | |
| 6709 if (p == null) return SqlBytes.Null; | |
| 6710 | |
| 6711 if (p is SqlBytes) return (SqlBytes)p; | |
| 6712 | |
| 6713 var type = p.GetType(); | |
| 6714 | |
| 6715 // Primitive types | |
| 6716 // | |
| 6717 switch (Type.GetTypeCode(type)) | |
| 6718 { | |
| 6719 case TypeCode.DBNull : return SqlBytes.Null; | |
| 6720 case TypeCode.String : return ToSqlBytes((String) p); | |
| 6721 case TypeCode.Byte : return ToSqlBytes((Byte) p); | |
| 6722 case TypeCode.SByte : return ToSqlBytes((SByte) p); | |
| 6723 case TypeCode.DateTime : return ToSqlBytes((DateTime)p); | |
| 6724 case TypeCode.Int16 : return ToSqlBytes((Int16) p); | |
| 6725 case TypeCode.Int32 : return ToSqlBytes((Int32) p); | |
| 6726 case TypeCode.Int64 : return ToSqlBytes((Int64) p); | |
| 6727 case TypeCode.UInt16 : return ToSqlBytes((UInt16) p); | |
| 6728 case TypeCode.UInt32 : return ToSqlBytes((UInt32) p); | |
| 6729 case TypeCode.UInt64 : return ToSqlBytes((UInt64) p); | |
| 6730 case TypeCode.Single : return ToSqlBytes((Single) p); | |
| 6731 case TypeCode.Double : return ToSqlBytes((Double) p); | |
| 6732 case TypeCode.Boolean : return ToSqlBytes((Boolean) p); | |
| 6733 case TypeCode.Char : return ToSqlBytes((Char) p); | |
| 6734 } | |
| 6735 | |
| 6736 // Simple Types | |
| 6737 // | |
| 6738 if (p is DateTimeOffset) return ToSqlBytes((DateTimeOffset) p); | |
| 6739 if (p is Guid) return ToSqlBytes((Guid) p); | |
| 6740 if (p is TimeSpan) return ToSqlBytes((TimeSpan) p); | |
| 6741 | |
| 6742 // Nullable Types | |
| 6743 // | |
| 6744 if (type.IsGenericType) | |
| 6745 { | |
| 6746 if (p is Boolean?) return ToSqlBytes((Boolean?) p); | |
| 6747 if (p is Byte?) return ToSqlBytes((Byte?) p); | |
| 6748 if (p is Char?) return ToSqlBytes((Char?) p); | |
| 6749 if (p is DateTime?) return ToSqlBytes((DateTime?) p); | |
| 6750 if (p is DateTimeOffset?) return ToSqlBytes((DateTimeOffset?)p); | |
| 6751 if (p is Decimal?) return ToSqlBytes((Decimal?) p); | |
| 6752 if (p is Double?) return ToSqlBytes((Double?) p); | |
| 6753 if (p is Guid?) return ToSqlBytes((Guid?) p); | |
| 6754 if (p is Int16?) return ToSqlBytes((Int16?) p); | |
| 6755 if (p is Int32?) return ToSqlBytes((Int32?) p); | |
| 6756 if (p is Int64?) return ToSqlBytes((Int64?) p); | |
| 6757 if (p is SByte?) return ToSqlBytes((SByte?) p); | |
| 6758 if (p is Single?) return ToSqlBytes((Single?) p); | |
| 6759 if (p is TimeSpan?) return ToSqlBytes((TimeSpan?) p); | |
| 6760 if (p is UInt16?) return ToSqlBytes((UInt16?) p); | |
| 6761 if (p is UInt32?) return ToSqlBytes((UInt32?) p); | |
| 6762 if (p is UInt64?) return ToSqlBytes((UInt64?) p); | |
| 6763 } | |
| 6764 | |
| 6765 // Sql Types | |
| 6766 // | |
| 6767 if (p is INullable) | |
| 6768 { | |
| 6769 if (p is SqlBinary) return ToSqlBytes((SqlBinary) p); | |
| 6770 if (p is SqlGuid) return ToSqlBytes((SqlGuid) p); | |
| 6771 } | |
| 6772 | |
| 6773 // Other Types | |
| 6774 // | |
| 6775 if (p is Binary) return ToSqlBytes((Binary) p); | |
| 6776 if (p is Byte[]) return ToSqlBytes((Byte[]) p); | |
| 6777 if (p is Stream) return ToSqlBytes((Stream) p); | |
| 6778 | |
| 6779 throw CreateInvalidCastException(p.GetType(), typeof(SqlBytes)); | |
| 6780 } | |
| 6781 | |
| 6782 #endif | |
| 6783 | |
| 6784 #endregion | |
| 6785 | |
| 6786 #region SqlChars | |
| 6787 | |
| 6788 #if !SILVERLIGHT | |
| 6789 | |
| 6790 #endif | |
| 6791 | |
| 6792 #endregion | |
| 6793 | |
| 6794 #region SqlDateTime | |
| 6795 | |
| 6796 #if !SILVERLIGHT | |
| 6797 | |
| 6798 // Simple Types | |
| 6799 // | |
| 6800 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6801 public static SqlDateTime ToSqlDateTime(DateTime p) { return p; } | |
| 6802 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6803 public static SqlDateTime ToSqlDateTime(DateTimeOffset p) { return p.LocalDateTime; } | |
| 6804 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6805 public static SqlDateTime ToSqlDateTime(Double p) { return DateTime.MinValue + TimeSpan.FromDays (p); } | |
| 6806 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6807 public static SqlDateTime ToSqlDateTime(Int64 p) { return DateTime.MinValue + TimeSpan.FromTicks(p); } | |
| 6808 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6809 public static SqlDateTime ToSqlDateTime(String p) { return p == null ? SqlDateTime.Null : DateTime.Parse(p, null, DateTimeStyles.NoCurrentDateDefault); } | |
| 6810 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6811 public static SqlDateTime ToSqlDateTime(TimeSpan p) { return DateTime.MinValue + p; } | |
| 6812 | |
| 6813 // Nullable Types | |
| 6814 // | |
| 6815 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6816 public static SqlDateTime ToSqlDateTime(DateTime? p) { return p.HasValue ? p.Value : SqlDateTime.Null; } | |
| 6817 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6818 public static SqlDateTime ToSqlDateTime(DateTimeOffset? p) { return p.HasValue ? p.Value.LocalDateTime : SqlDateTime.Null; } | |
| 6819 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6820 public static SqlDateTime ToSqlDateTime(Double? p) { return p.HasValue ? DateTime.MinValue + TimeSpan.FromDays (p.Value): SqlDateTime.Null; } | |
| 6821 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6822 public static SqlDateTime ToSqlDateTime(Int64? p) { return p.HasValue ? DateTime.MinValue + TimeSpan.FromTicks(p.Value): SqlDateTime.Null; } | |
| 6823 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6824 public static SqlDateTime ToSqlDateTime(TimeSpan? p) { return p.HasValue ? DateTime.MinValue + p.Value : SqlDateTime.Null; } | |
| 6825 | |
| 6826 // Sql Types | |
| 6827 // | |
| 6828 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6829 public static SqlDateTime ToSqlDateTime(SqlDouble p) { return p.IsNull ? SqlDateTime.Null : DateTime.MinValue + TimeSpan.FromDays (p.Value); } | |
| 6830 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6831 public static SqlDateTime ToSqlDateTime(SqlInt64 p) { return p.IsNull ? SqlDateTime.Null : DateTime.MinValue + TimeSpan.FromTicks(p.Value); } | |
| 6832 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6833 public static SqlDateTime ToSqlDateTime(SqlString p) { return p.IsNull ? SqlDateTime.Null : ToDateTime(p.Value); } | |
| 6834 | |
| 6835 // Other Types | |
| 6836 // | |
| 6837 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6838 public static SqlDateTime ToSqlDateTime(Binary p) { return p == null || p.Length == 0 ? SqlDateTime.Null : DateTime.FromBinary(ToInt64(p.ToArray())); } | |
| 6839 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6840 public static SqlDateTime ToSqlDateTime(Byte[] p) { return p == null || p.Length == 0 ? SqlDateTime.Null : DateTime.FromBinary(ToInt64(p)); } | |
| 6841 | |
| 6842 // From Object | |
| 6843 // | |
| 6844 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlDateTime</c> value.</summary> | |
| 6845 public static SqlDateTime ToSqlDateTime(object p) | |
| 6846 { | |
| 6847 if (p == null) return SqlDateTime.Null; | |
| 6848 | |
| 6849 if (p is SqlDateTime) return (SqlDateTime)p; | |
| 6850 | |
| 6851 var type = p.GetType(); | |
| 6852 | |
| 6853 // Primitive types | |
| 6854 // | |
| 6855 switch (Type.GetTypeCode(type)) | |
| 6856 { | |
| 6857 case TypeCode.DBNull : return SqlDateTime.Null; | |
| 6858 case TypeCode.DateTime : return ToSqlDateTime((DateTime) p); | |
| 6859 case TypeCode.String : return ToSqlDateTime((String) p); | |
| 6860 case TypeCode.Int64 : return ToSqlDateTime((Int64) p); | |
| 6861 case TypeCode.Double : return ToSqlDateTime((Double) p); | |
| 6862 } | |
| 6863 | |
| 6864 // Simple Types | |
| 6865 // | |
| 6866 if (p is DateTimeOffset) return ToSqlDateTime((DateTimeOffset) p); | |
| 6867 if (p is TimeSpan) return ToSqlDateTime((TimeSpan) p); | |
| 6868 | |
| 6869 // Nullable Types | |
| 6870 // | |
| 6871 if (type.IsGenericType) | |
| 6872 { | |
| 6873 if (p is DateTime?) return ToSqlDateTime((DateTime?) p); | |
| 6874 if (p is DateTimeOffset?) return ToSqlDateTime((DateTimeOffset?)p); | |
| 6875 if (p is Double?) return ToSqlDateTime((Double?) p); | |
| 6876 if (p is Int64?) return ToSqlDateTime((Int64?) p); | |
| 6877 if (p is TimeSpan?) return ToSqlDateTime((TimeSpan?) p); | |
| 6878 } | |
| 6879 | |
| 6880 // Sql Types | |
| 6881 // | |
| 6882 if (p is INullable) | |
| 6883 { | |
| 6884 if (p is SqlDouble) return ToSqlDateTime((SqlDouble) p); | |
| 6885 if (p is SqlInt64) return ToSqlDateTime((SqlInt64) p); | |
| 6886 if (p is SqlString) return ToSqlDateTime((SqlString) p); | |
| 6887 } | |
| 6888 | |
| 6889 // Other Types | |
| 6890 // | |
| 6891 if (p is Binary) return ToSqlDateTime((Binary) p); | |
| 6892 if (p is Byte[]) return ToSqlDateTime((Byte[]) p); | |
| 6893 | |
| 6894 throw CreateInvalidCastException(p.GetType(), typeof(SqlDateTime)); | |
| 6895 } | |
| 6896 | |
| 6897 #endif | |
| 6898 | |
| 6899 #endregion | |
| 6900 | |
| 6901 #region SqlDecimal | |
| 6902 | |
| 6903 #if !SILVERLIGHT | |
| 6904 | |
| 6905 // Simple Types | |
| 6906 // | |
| 6907 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6908 public static SqlDecimal ToSqlDecimal(Boolean p) { return p ? (SqlDecimal)1 : (SqlDecimal)0; } | |
| 6909 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6910 public static SqlDecimal ToSqlDecimal(Byte p) { return p; } | |
| 6911 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6912 public static SqlDecimal ToSqlDecimal(Char p) { return p; } | |
| 6913 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6914 public static SqlDecimal ToSqlDecimal(Decimal p) { return p; } | |
| 6915 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6916 public static SqlDecimal ToSqlDecimal(Double p) { return checked((Decimal)p); } | |
| 6917 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6918 public static SqlDecimal ToSqlDecimal(Int16 p) { return p; } | |
| 6919 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6920 public static SqlDecimal ToSqlDecimal(Int32 p) { return p; } | |
| 6921 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6922 public static SqlDecimal ToSqlDecimal(Int64 p) { return p; } | |
| 6923 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6924 [CLSCompliant(false)] | |
| 6925 public static SqlDecimal ToSqlDecimal(SByte p) { return p; } | |
| 6926 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6927 public static SqlDecimal ToSqlDecimal(Single p) { return checked((Decimal)p); } | |
| 6928 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6929 public static SqlDecimal ToSqlDecimal(String p) { return p == null? SqlDecimal.Null : Decimal.Parse(p); } | |
| 6930 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6931 [CLSCompliant(false)] | |
| 6932 public static SqlDecimal ToSqlDecimal(UInt16 p) { return p; } | |
| 6933 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6934 [CLSCompliant(false)] | |
| 6935 public static SqlDecimal ToSqlDecimal(UInt32 p) { return p; } | |
| 6936 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6937 [CLSCompliant(false)] | |
| 6938 public static SqlDecimal ToSqlDecimal(UInt64 p) { return p; } | |
| 6939 | |
| 6940 // Nullable Types | |
| 6941 // | |
| 6942 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6943 public static SqlDecimal ToSqlDecimal(Boolean? p) { return p.HasValue && p.Value ? (SqlDecimal)1: (SqlDecimal)0; } | |
| 6944 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6945 public static SqlDecimal ToSqlDecimal(Byte? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6946 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6947 public static SqlDecimal ToSqlDecimal(Char? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6948 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6949 public static SqlDecimal ToSqlDecimal(Decimal? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6950 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6951 public static SqlDecimal ToSqlDecimal(Double? p) { return p.HasValue ? checked((Decimal)p.Value) : SqlDecimal.Null; } | |
| 6952 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6953 public static SqlDecimal ToSqlDecimal(Int16? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6954 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6955 public static SqlDecimal ToSqlDecimal(Int32? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6956 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6957 public static SqlDecimal ToSqlDecimal(Int64? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6958 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6959 [CLSCompliant(false)] | |
| 6960 public static SqlDecimal ToSqlDecimal(SByte? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6961 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6962 public static SqlDecimal ToSqlDecimal(Single? p) { return p.HasValue ? checked((Decimal)p.Value) : SqlDecimal.Null; } | |
| 6963 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6964 [CLSCompliant(false)] | |
| 6965 public static SqlDecimal ToSqlDecimal(UInt16? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6966 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6967 [CLSCompliant(false)] | |
| 6968 public static SqlDecimal ToSqlDecimal(UInt32? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6969 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6970 [CLSCompliant(false)] | |
| 6971 public static SqlDecimal ToSqlDecimal(UInt64? p) { return p.HasValue ? p.Value : SqlDecimal.Null; } | |
| 6972 | |
| 6973 // Sql Types | |
| 6974 // | |
| 6975 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6976 public static SqlDecimal ToSqlDecimal(SqlBoolean p) { return p.ToSqlDecimal(); } | |
| 6977 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6978 public static SqlDecimal ToSqlDecimal(SqlByte p) { return p.ToSqlDecimal(); } | |
| 6979 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6980 public static SqlDecimal ToSqlDecimal(SqlDouble p) { return p.ToSqlDecimal(); } | |
| 6981 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6982 public static SqlDecimal ToSqlDecimal(SqlInt16 p) { return p.ToSqlDecimal(); } | |
| 6983 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6984 public static SqlDecimal ToSqlDecimal(SqlInt32 p) { return p.ToSqlDecimal(); } | |
| 6985 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6986 public static SqlDecimal ToSqlDecimal(SqlInt64 p) { return p.ToSqlDecimal(); } | |
| 6987 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6988 public static SqlDecimal ToSqlDecimal(SqlMoney p) { return p.ToSqlDecimal(); } | |
| 6989 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6990 public static SqlDecimal ToSqlDecimal(SqlSingle p) { return p.ToSqlDecimal(); } | |
| 6991 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6992 public static SqlDecimal ToSqlDecimal(SqlString p) { return p.ToSqlDecimal(); } | |
| 6993 | |
| 6994 // Other Types | |
| 6995 // | |
| 6996 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6997 public static SqlDecimal ToSqlDecimal(Binary p) { return p == null || p.Length == 0 ? SqlDecimal.Null : ToDecimal(p); } | |
| 6998 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 6999 public static SqlDecimal ToSqlDecimal(Byte[] p) { return p == null || p.Length == 0 ? SqlDecimal.Null : ToDecimal(p); } | |
| 7000 | |
| 7001 // From Object | |
| 7002 // | |
| 7003 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlDecimal</c> value.</summary> | |
| 7004 public static SqlDecimal ToSqlDecimal(object p) | |
| 7005 { | |
| 7006 if (p == null) return SqlDecimal.Null; | |
| 7007 | |
| 7008 if (p is SqlDecimal) return (SqlDecimal)p; | |
| 7009 | |
| 7010 var type = p.GetType(); | |
| 7011 | |
| 7012 // Primitive types | |
| 7013 // | |
| 7014 switch (Type.GetTypeCode(type)) | |
| 7015 { | |
| 7016 case TypeCode.DBNull : return SqlDecimal.Null; | |
| 7017 case TypeCode.SByte : return ToSqlDecimal((SByte) p); | |
| 7018 case TypeCode.Int16 : return ToSqlDecimal((Int16) p); | |
| 7019 case TypeCode.Int32 : return ToSqlDecimal((Int32) p); | |
| 7020 case TypeCode.Int64 : return ToSqlDecimal((Int64) p); | |
| 7021 case TypeCode.Byte : return ToSqlDecimal((Byte) p); | |
| 7022 case TypeCode.UInt16 : return ToSqlDecimal((UInt16) p); | |
| 7023 case TypeCode.UInt32 : return ToSqlDecimal((UInt32) p); | |
| 7024 case TypeCode.Char : return ToSqlDecimal((Char) p); | |
| 7025 case TypeCode.UInt64 : return ToSqlDecimal((UInt64) p); | |
| 7026 case TypeCode.Decimal : return ToSqlDecimal((Decimal) p); | |
| 7027 case TypeCode.Single : return ToSqlDecimal((Single) p); | |
| 7028 case TypeCode.Double : return ToSqlDecimal((Double) p); | |
| 7029 case TypeCode.String : return ToSqlDecimal((String) p); | |
| 7030 case TypeCode.Boolean : return ToSqlDecimal((Boolean) p); | |
| 7031 } | |
| 7032 | |
| 7033 // Nullable Types | |
| 7034 // | |
| 7035 if (type.IsGenericType) | |
| 7036 { | |
| 7037 if (p is Boolean?) return ToSqlDecimal((Boolean?) p); | |
| 7038 if (p is Byte?) return ToSqlDecimal((Byte?) p); | |
| 7039 if (p is Char?) return ToSqlDecimal((Char?) p); | |
| 7040 if (p is Decimal?) return ToSqlDecimal((Decimal?) p); | |
| 7041 if (p is Double?) return ToSqlDecimal((Double?) p); | |
| 7042 if (p is Int16?) return ToSqlDecimal((Int16?) p); | |
| 7043 if (p is Int32?) return ToSqlDecimal((Int32?) p); | |
| 7044 if (p is Int64?) return ToSqlDecimal((Int64?) p); | |
| 7045 if (p is SByte?) return ToSqlDecimal((SByte?) p); | |
| 7046 if (p is Single?) return ToSqlDecimal((Single?) p); | |
| 7047 if (p is UInt16?) return ToSqlDecimal((UInt16?) p); | |
| 7048 if (p is UInt32?) return ToSqlDecimal((UInt32?) p); | |
| 7049 if (p is UInt64?) return ToSqlDecimal((UInt64?) p); | |
| 7050 } | |
| 7051 | |
| 7052 // Sql Types | |
| 7053 // | |
| 7054 if (p is INullable) | |
| 7055 { | |
| 7056 if (p is SqlBoolean) return ToSqlDecimal((SqlBoolean)p); | |
| 7057 if (p is SqlByte) return ToSqlDecimal((SqlByte) p); | |
| 7058 if (p is SqlDouble) return ToSqlDecimal((SqlDouble) p); | |
| 7059 if (p is SqlInt16) return ToSqlDecimal((SqlInt16) p); | |
| 7060 if (p is SqlInt32) return ToSqlDecimal((SqlInt32) p); | |
| 7061 if (p is SqlInt64) return ToSqlDecimal((SqlInt64) p); | |
| 7062 if (p is SqlMoney) return ToSqlDecimal((SqlMoney) p); | |
| 7063 if (p is SqlSingle) return ToSqlDecimal((SqlSingle) p); | |
| 7064 if (p is SqlString) return ToSqlDecimal((SqlString) p); | |
| 7065 } | |
| 7066 | |
| 7067 // Other Types | |
| 7068 // | |
| 7069 if (p is Binary) return ToSqlDecimal((Binary) p); | |
| 7070 if (p is Byte[]) return ToSqlDecimal((Byte[]) p); | |
| 7071 | |
| 7072 throw CreateInvalidCastException(p.GetType(), typeof(SqlDecimal)); | |
| 7073 } | |
| 7074 | |
| 7075 #endif | |
| 7076 | |
| 7077 #endregion | |
| 7078 | |
| 7079 #region SqlDouble | |
| 7080 | |
| 7081 #if !SILVERLIGHT | |
| 7082 | |
| 7083 // Simple Types | |
| 7084 // | |
| 7085 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7086 public static SqlDouble ToSqlDouble(Boolean p) { return p ? (SqlDouble)1 : (SqlDouble)0; } | |
| 7087 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7088 public static SqlDouble ToSqlDouble(Byte p) { return p; } | |
| 7089 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7090 public static SqlDouble ToSqlDouble(Char p) { return p; } | |
| 7091 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7092 public static SqlDouble ToSqlDouble(DateTime p) { return (p - DateTime.MinValue).TotalDays; } | |
| 7093 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7094 public static SqlDouble ToSqlDouble(DateTimeOffset p) { return (p - DateTimeOffset.MinValue).TotalDays; } | |
| 7095 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7096 public static SqlDouble ToSqlDouble(Decimal p) { return checked((Double)p); } | |
| 7097 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7098 public static SqlDouble ToSqlDouble(Double p) { return p; } | |
| 7099 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7100 public static SqlDouble ToSqlDouble(Int16 p) { return p; } | |
| 7101 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7102 public static SqlDouble ToSqlDouble(Int32 p) { return p; } | |
| 7103 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7104 public static SqlDouble ToSqlDouble(Int64 p) { return p; } | |
| 7105 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7106 [CLSCompliant(false)] | |
| 7107 public static SqlDouble ToSqlDouble(SByte p) { return p; } | |
| 7108 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7109 public static SqlDouble ToSqlDouble(Single p) { return p; } | |
| 7110 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7111 public static SqlDouble ToSqlDouble(String p) { return p == null? SqlDouble.Null : Double.Parse(p); } | |
| 7112 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7113 public static SqlDouble ToSqlDouble(TimeSpan p) { return p.TotalDays; } | |
| 7114 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7115 [CLSCompliant(false)] | |
| 7116 public static SqlDouble ToSqlDouble(UInt16 p) { return p; } | |
| 7117 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7118 [CLSCompliant(false)] | |
| 7119 public static SqlDouble ToSqlDouble(UInt32 p) { return p; } | |
| 7120 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7121 [CLSCompliant(false)] | |
| 7122 public static SqlDouble ToSqlDouble(UInt64 p) { return p; } | |
| 7123 | |
| 7124 // Nullable Types | |
| 7125 // | |
| 7126 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7127 public static SqlDouble ToSqlDouble(Boolean? p) { return p.HasValue && p.Value ? (SqlDouble)1: (SqlDouble)0; } | |
| 7128 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7129 public static SqlDouble ToSqlDouble(Byte? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7130 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7131 public static SqlDouble ToSqlDouble(Char? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7132 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7133 public static SqlDouble ToSqlDouble(DateTime? p) { return p.HasValue ? (p.Value - DateTime.MinValue).TotalDays : SqlDouble.Null; } | |
| 7134 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7135 public static SqlDouble ToSqlDouble(DateTimeOffset? p) { return p.HasValue ? (p.Value - DateTimeOffset.MinValue).TotalDays : SqlDouble.Null; } | |
| 7136 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7137 public static SqlDouble ToSqlDouble(Decimal? p) { return p.HasValue ? checked((Double)p.Value) : SqlDouble.Null; } | |
| 7138 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7139 public static SqlDouble ToSqlDouble(Double? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7140 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7141 public static SqlDouble ToSqlDouble(Int16? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7142 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7143 public static SqlDouble ToSqlDouble(Int32? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7144 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7145 public static SqlDouble ToSqlDouble(Int64? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7146 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7147 [CLSCompliant(false)] | |
| 7148 public static SqlDouble ToSqlDouble(SByte? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7149 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7150 public static SqlDouble ToSqlDouble(Single? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7151 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7152 public static SqlDouble ToSqlDouble(TimeSpan? p) { return p.HasValue ? p.Value.TotalDays : SqlDouble.Null; } | |
| 7153 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7154 [CLSCompliant(false)] | |
| 7155 public static SqlDouble ToSqlDouble(UInt16? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7156 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7157 [CLSCompliant(false)] | |
| 7158 public static SqlDouble ToSqlDouble(UInt32? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7159 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7160 [CLSCompliant(false)] | |
| 7161 public static SqlDouble ToSqlDouble(UInt64? p) { return p.HasValue ? p.Value : SqlDouble.Null; } | |
| 7162 | |
| 7163 // Sql Types | |
| 7164 // | |
| 7165 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7166 public static SqlDouble ToSqlDouble(SqlBoolean p) { return p.ToSqlDouble(); } | |
| 7167 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7168 public static SqlDouble ToSqlDouble(SqlByte p) { return p.ToSqlDouble(); } | |
| 7169 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7170 public static SqlDouble ToSqlDouble(SqlDateTime p) { return p.IsNull? SqlDouble.Null: ToDouble(p.Value); } | |
| 7171 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7172 public static SqlDouble ToSqlDouble(SqlDecimal p) { return p.ToSqlDouble(); } | |
| 7173 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7174 public static SqlDouble ToSqlDouble(SqlInt16 p) { return p.ToSqlDouble(); } | |
| 7175 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7176 public static SqlDouble ToSqlDouble(SqlInt32 p) { return p.ToSqlDouble(); } | |
| 7177 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7178 public static SqlDouble ToSqlDouble(SqlInt64 p) { return p.ToSqlDouble(); } | |
| 7179 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7180 public static SqlDouble ToSqlDouble(SqlMoney p) { return p.ToSqlDouble(); } | |
| 7181 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7182 public static SqlDouble ToSqlDouble(SqlSingle p) { return p.ToSqlDouble(); } | |
| 7183 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7184 public static SqlDouble ToSqlDouble(SqlString p) { return p.ToSqlDouble(); } | |
| 7185 | |
| 7186 // Other Types | |
| 7187 // | |
| 7188 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7189 public static SqlDouble ToSqlDouble(Binary p) { return p == null || p.Length == 0 ? SqlDouble.Null : BitConverter.ToDouble(p.ToArray(), 0); } | |
| 7190 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7191 public static SqlDouble ToSqlDouble(Byte[] p) { return p == null || p.Length == 0 ? SqlDouble.Null : BitConverter.ToDouble(p, 0); } | |
| 7192 | |
| 7193 // From Object | |
| 7194 // | |
| 7195 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlDouble</c> value.</summary> | |
| 7196 public static SqlDouble ToSqlDouble(object p) | |
| 7197 { | |
| 7198 if (p == null) return SqlDouble.Null; | |
| 7199 | |
| 7200 if (p is SqlDouble) return (SqlDouble)p; | |
| 7201 | |
| 7202 var type = p.GetType(); | |
| 7203 | |
| 7204 // Primitive types | |
| 7205 // | |
| 7206 switch (Type.GetTypeCode(type)) | |
| 7207 { | |
| 7208 case TypeCode.DBNull : return SqlDouble.Null; | |
| 7209 case TypeCode.DateTime : return ToSqlDouble((DateTime) p); | |
| 7210 case TypeCode.SByte : return ToSqlDouble((SByte) p); | |
| 7211 case TypeCode.Int16 : return ToSqlDouble((Int16) p); | |
| 7212 case TypeCode.Int32 : return ToSqlDouble((Int32) p); | |
| 7213 case TypeCode.Int64 : return ToSqlDouble((Int64) p); | |
| 7214 case TypeCode.Byte : return ToSqlDouble((Byte) p); | |
| 7215 case TypeCode.UInt16 : return ToSqlDouble((UInt16) p); | |
| 7216 case TypeCode.UInt32 : return ToSqlDouble((UInt32) p); | |
| 7217 case TypeCode.Char : return ToSqlDouble((Char) p); | |
| 7218 case TypeCode.UInt64 : return ToSqlDouble((UInt64) p); | |
| 7219 case TypeCode.Single : return ToSqlDouble((Single) p); | |
| 7220 case TypeCode.Double : return ToSqlDouble((Double) p); | |
| 7221 case TypeCode.Decimal : return ToSqlDouble((Decimal) p); | |
| 7222 case TypeCode.String : return ToSqlDouble((String) p); | |
| 7223 case TypeCode.Boolean : return ToSqlDouble((Boolean) p); | |
| 7224 } | |
| 7225 | |
| 7226 // Simple Types | |
| 7227 // | |
| 7228 if (p is DateTimeOffset) return ToSqlDouble((DateTimeOffset) p); | |
| 7229 if (p is TimeSpan) return ToSqlDouble((TimeSpan) p); | |
| 7230 | |
| 7231 // Nullable Types | |
| 7232 // | |
| 7233 if (type.IsGenericType) | |
| 7234 { | |
| 7235 if (p is Boolean?) return ToSqlDouble((Boolean?) p); | |
| 7236 if (p is Byte?) return ToSqlDouble((Byte?) p); | |
| 7237 if (p is Char?) return ToSqlDouble((Char?) p); | |
| 7238 if (p is DateTime?) return ToSqlDouble((DateTime?) p); | |
| 7239 if (p is DateTimeOffset?) return ToSqlDouble((DateTimeOffset?)p); | |
| 7240 if (p is Decimal?) return ToSqlDouble((Decimal?) p); | |
| 7241 if (p is Double?) return ToSqlDouble((Double?) p); | |
| 7242 if (p is Int16?) return ToSqlDouble((Int16?) p); | |
| 7243 if (p is Int32?) return ToSqlDouble((Int32?) p); | |
| 7244 if (p is Int64?) return ToSqlDouble((Int64?) p); | |
| 7245 if (p is SByte?) return ToSqlDouble((SByte?) p); | |
| 7246 if (p is Single?) return ToSqlDouble((Single?) p); | |
| 7247 if (p is TimeSpan?) return ToSqlDouble((TimeSpan?) p); | |
| 7248 if (p is UInt16?) return ToSqlDouble((UInt16?) p); | |
| 7249 if (p is UInt32?) return ToSqlDouble((UInt32?) p); | |
| 7250 if (p is UInt64?) return ToSqlDouble((UInt64?) p); | |
| 7251 } | |
| 7252 | |
| 7253 // Sql Types | |
| 7254 // | |
| 7255 if (p is INullable) | |
| 7256 { | |
| 7257 if (p is SqlBoolean) return ToSqlDouble((SqlBoolean) p); | |
| 7258 if (p is SqlByte) return ToSqlDouble((SqlByte) p); | |
| 7259 if (p is SqlDateTime) return ToSqlDouble((SqlDateTime) p); | |
| 7260 if (p is SqlDecimal) return ToSqlDouble((SqlDecimal) p); | |
| 7261 if (p is SqlInt16) return ToSqlDouble((SqlInt16) p); | |
| 7262 if (p is SqlInt32) return ToSqlDouble((SqlInt32) p); | |
| 7263 if (p is SqlInt64) return ToSqlDouble((SqlInt64) p); | |
| 7264 if (p is SqlMoney) return ToSqlDouble((SqlMoney) p); | |
| 7265 if (p is SqlSingle) return ToSqlDouble((SqlSingle) p); | |
| 7266 if (p is SqlString) return ToSqlDouble((SqlString) p); | |
| 7267 } | |
| 7268 | |
| 7269 // Other Types | |
| 7270 // | |
| 7271 if (p is Binary) return ToSqlDouble((Binary) p); | |
| 7272 if (p is Byte[]) return ToSqlDouble((Byte[]) p); | |
| 7273 | |
| 7274 throw CreateInvalidCastException(p.GetType(), typeof(SqlDouble)); | |
| 7275 } | |
| 7276 | |
| 7277 #endif | |
| 7278 | |
| 7279 #endregion | |
| 7280 | |
| 7281 #region SqlGuid | |
| 7282 | |
| 7283 #if !SILVERLIGHT | |
| 7284 | |
| 7285 // Simple Types | |
| 7286 // | |
| 7287 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7288 public static SqlGuid ToSqlGuid(Guid p) { return p; } | |
| 7289 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7290 public static SqlGuid ToSqlGuid(String p) { return p == null ? SqlGuid.Null : new Guid(p); } | |
| 7291 | |
| 7292 // Nullable Types | |
| 7293 // | |
| 7294 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7295 public static SqlGuid ToSqlGuid(Guid? p) { return p.HasValue ? p.Value : SqlGuid.Null; } | |
| 7296 | |
| 7297 // Sql Types | |
| 7298 // | |
| 7299 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7300 public static SqlGuid ToSqlGuid(SqlBinary p) { return p.IsNull ? SqlGuid.Null : p.ToSqlGuid().Value; } | |
| 7301 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7302 public static SqlGuid ToSqlGuid(SqlString p) { return p.IsNull ? SqlGuid.Null : new Guid(p.Value); } | |
| 7303 | |
| 7304 // Other Types | |
| 7305 // | |
| 7306 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7307 public static SqlGuid ToSqlGuid(Binary p) { return p == null ? SqlGuid.Null : new Guid(p.ToArray()); } | |
| 7308 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7309 public static SqlGuid ToSqlGuid(Byte[] p) { return p == null ? SqlGuid.Null : new Guid(p); } | |
| 7310 /// <summary>Converts the value from <c>Type</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7311 public static SqlGuid ToSqlGuid(Type p) { return p == null ? SqlGuid.Null : p.GUID; } | |
| 7312 | |
| 7313 // From Object | |
| 7314 // | |
| 7315 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlGuid</c> value.</summary> | |
| 7316 public static SqlGuid ToSqlGuid(object p) | |
| 7317 { | |
| 7318 if (p == null) return SqlGuid.Null; | |
| 7319 | |
| 7320 if (p is SqlGuid) return (SqlGuid)p; | |
| 7321 | |
| 7322 var type = p.GetType(); | |
| 7323 | |
| 7324 // Primitive types | |
| 7325 // | |
| 7326 switch (Type.GetTypeCode(type)) | |
| 7327 { | |
| 7328 case TypeCode.DBNull : return SqlGuid.Null; | |
| 7329 case TypeCode.String : return ToSqlGuid((String) p); | |
| 7330 } | |
| 7331 | |
| 7332 // Simple Types | |
| 7333 // | |
| 7334 if (p is Guid) return ToSqlGuid((Guid) p); | |
| 7335 | |
| 7336 // Nullable Types | |
| 7337 // | |
| 7338 if (type.IsGenericType) | |
| 7339 { | |
| 7340 if (p is Guid?) return ToSqlGuid((Guid?) p); | |
| 7341 } | |
| 7342 | |
| 7343 // Sql Types | |
| 7344 // | |
| 7345 if (p is INullable) | |
| 7346 { | |
| 7347 if (p is SqlBinary) return ToSqlGuid((SqlBinary)p); | |
| 7348 if (p is SqlString) return ToSqlGuid((SqlString)p); | |
| 7349 } | |
| 7350 | |
| 7351 // Other Types | |
| 7352 // | |
| 7353 if (p is Binary) return ToSqlGuid((Binary) p); | |
| 7354 if (p is Byte[]) return ToSqlGuid((Byte[]) p); | |
| 7355 if (p is Type) return ToSqlGuid((Type) p); | |
| 7356 | |
| 7357 throw CreateInvalidCastException(p.GetType(), typeof(SqlGuid)); | |
| 7358 } | |
| 7359 | |
| 7360 #endif | |
| 7361 | |
| 7362 #endregion | |
| 7363 | |
| 7364 #region SqlInt16 | |
| 7365 | |
| 7366 #if !SILVERLIGHT | |
| 7367 | |
| 7368 // Simple Types | |
| 7369 // | |
| 7370 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7371 public static SqlInt16 ToSqlInt16(Boolean p) { return p ? (SqlInt16)1 : (SqlInt16)0; } | |
| 7372 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7373 public static SqlInt16 ToSqlInt16(Byte p) { return p; } | |
| 7374 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7375 public static SqlInt16 ToSqlInt16(Char p) { return checked((Int16)p); } | |
| 7376 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7377 public static SqlInt16 ToSqlInt16(Decimal p) { return checked((Int16)p); } | |
| 7378 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7379 public static SqlInt16 ToSqlInt16(Double p) { return checked((Int16)p); } | |
| 7380 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7381 public static SqlInt16 ToSqlInt16(Int16 p) { return p; } | |
| 7382 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7383 public static SqlInt16 ToSqlInt16(Int32 p) { return checked((Int16)p); } | |
| 7384 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7385 public static SqlInt16 ToSqlInt16(Int64 p) { return checked((Int16)p); } | |
| 7386 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7387 [CLSCompliant(false)] | |
| 7388 public static SqlInt16 ToSqlInt16(SByte p) { return p; } | |
| 7389 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7390 public static SqlInt16 ToSqlInt16(Single p) { return checked((Int16)p); } | |
| 7391 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7392 public static SqlInt16 ToSqlInt16(String p) { return p == null? SqlInt16.Null : Int16.Parse(p); } | |
| 7393 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7394 [CLSCompliant(false)] | |
| 7395 public static SqlInt16 ToSqlInt16(UInt16 p) { return checked((Int16)p); } | |
| 7396 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7397 [CLSCompliant(false)] | |
| 7398 public static SqlInt16 ToSqlInt16(UInt32 p) { return checked((Int16)p); } | |
| 7399 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7400 [CLSCompliant(false)] | |
| 7401 public static SqlInt16 ToSqlInt16(UInt64 p) { return checked((Int16)p); } | |
| 7402 | |
| 7403 // Nullable Types | |
| 7404 // | |
| 7405 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7406 public static SqlInt16 ToSqlInt16(Boolean? p) { return p.HasValue && p.Value ? (SqlInt16)1: (SqlInt16)0; } | |
| 7407 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7408 public static SqlInt16 ToSqlInt16(Byte? p) { return p.HasValue ? p.Value : SqlInt16.Null; } | |
| 7409 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7410 public static SqlInt16 ToSqlInt16(Char? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7411 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7412 public static SqlInt16 ToSqlInt16(Decimal? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7413 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7414 public static SqlInt16 ToSqlInt16(Double? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7415 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7416 public static SqlInt16 ToSqlInt16(Int16? p) { return p.HasValue ? p.Value : SqlInt16.Null; } | |
| 7417 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7418 public static SqlInt16 ToSqlInt16(Int32? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7419 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7420 public static SqlInt16 ToSqlInt16(Int64? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7421 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7422 [CLSCompliant(false)] | |
| 7423 public static SqlInt16 ToSqlInt16(SByte? p) { return p.HasValue ? p.Value : SqlInt16.Null; } | |
| 7424 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7425 public static SqlInt16 ToSqlInt16(Single? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7426 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7427 [CLSCompliant(false)] | |
| 7428 public static SqlInt16 ToSqlInt16(UInt16? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7429 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7430 [CLSCompliant(false)] | |
| 7431 public static SqlInt16 ToSqlInt16(UInt32? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7432 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7433 [CLSCompliant(false)] | |
| 7434 public static SqlInt16 ToSqlInt16(UInt64? p) { return p.HasValue ? checked((Int16)p.Value) : SqlInt16.Null; } | |
| 7435 | |
| 7436 // Sql Types | |
| 7437 // | |
| 7438 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7439 public static SqlInt16 ToSqlInt16(SqlBoolean p) { return p.ToSqlInt16(); } | |
| 7440 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7441 public static SqlInt16 ToSqlInt16(SqlByte p) { return p.ToSqlInt16(); } | |
| 7442 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7443 public static SqlInt16 ToSqlInt16(SqlDecimal p) { return p.ToSqlInt16(); } | |
| 7444 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7445 public static SqlInt16 ToSqlInt16(SqlDouble p) { return p.ToSqlInt16(); } | |
| 7446 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7447 public static SqlInt16 ToSqlInt16(SqlInt32 p) { return p.ToSqlInt16(); } | |
| 7448 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7449 public static SqlInt16 ToSqlInt16(SqlInt64 p) { return p.ToSqlInt16(); } | |
| 7450 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7451 public static SqlInt16 ToSqlInt16(SqlMoney p) { return p.ToSqlInt16(); } | |
| 7452 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7453 public static SqlInt16 ToSqlInt16(SqlSingle p) { return p.ToSqlInt16(); } | |
| 7454 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7455 public static SqlInt16 ToSqlInt16(SqlString p) { return p.ToSqlInt16(); } | |
| 7456 | |
| 7457 // Other Types | |
| 7458 // | |
| 7459 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7460 public static SqlInt16 ToSqlInt16(Binary p) { return p == null || p.Length == 0 ? SqlInt16.Null : BitConverter.ToInt16(p.ToArray(), 0); } | |
| 7461 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7462 public static SqlInt16 ToSqlInt16(Byte[] p) { return p == null || p.Length == 0 ? SqlInt16.Null : BitConverter.ToInt16(p, 0); } | |
| 7463 | |
| 7464 // From Object | |
| 7465 // | |
| 7466 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlInt16</c> value.</summary> | |
| 7467 public static SqlInt16 ToSqlInt16(object p) | |
| 7468 { | |
| 7469 if (p == null) return SqlInt16.Null; | |
| 7470 | |
| 7471 if (p is SqlInt16) return (SqlInt16)p; | |
| 7472 | |
| 7473 var type = p.GetType(); | |
| 7474 | |
| 7475 // Primitive types | |
| 7476 // | |
| 7477 switch (Type.GetTypeCode(type)) | |
| 7478 { | |
| 7479 case TypeCode.DBNull : return SqlInt16.Null; | |
| 7480 case TypeCode.SByte : return ToSqlInt16((SByte) p); | |
| 7481 case TypeCode.Int16 : return ToSqlInt16((Int16) p); | |
| 7482 case TypeCode.Byte : return ToSqlInt16((Byte) p); | |
| 7483 case TypeCode.Int32 : return ToSqlInt16((Int32) p); | |
| 7484 case TypeCode.Int64 : return ToSqlInt16((Int64) p); | |
| 7485 case TypeCode.UInt16 : return ToSqlInt16((UInt16) p); | |
| 7486 case TypeCode.UInt32 : return ToSqlInt16((UInt32) p); | |
| 7487 case TypeCode.UInt64 : return ToSqlInt16((UInt64) p); | |
| 7488 case TypeCode.Single : return ToSqlInt16((Single) p); | |
| 7489 case TypeCode.Double : return ToSqlInt16((Double) p); | |
| 7490 case TypeCode.Decimal : return ToSqlInt16((Decimal) p); | |
| 7491 case TypeCode.Char : return ToSqlInt16((Char) p); | |
| 7492 case TypeCode.String : return ToSqlInt16((String) p); | |
| 7493 case TypeCode.Boolean : return ToSqlInt16((Boolean) p); | |
| 7494 } | |
| 7495 | |
| 7496 // Nullable Types | |
| 7497 // | |
| 7498 if (type.IsGenericType) | |
| 7499 { | |
| 7500 if (p is Boolean?) return ToSqlInt16((Boolean?) p); | |
| 7501 if (p is Byte?) return ToSqlInt16((Byte?) p); | |
| 7502 if (p is Char?) return ToSqlInt16((Char?) p); | |
| 7503 if (p is Decimal?) return ToSqlInt16((Decimal?) p); | |
| 7504 if (p is Double?) return ToSqlInt16((Double?) p); | |
| 7505 if (p is Int16?) return ToSqlInt16((Int16?) p); | |
| 7506 if (p is Int32?) return ToSqlInt16((Int32?) p); | |
| 7507 if (p is Int64?) return ToSqlInt16((Int64?) p); | |
| 7508 if (p is SByte?) return ToSqlInt16((SByte?) p); | |
| 7509 if (p is Single?) return ToSqlInt16((Single?) p); | |
| 7510 if (p is UInt16?) return ToSqlInt16((UInt16?) p); | |
| 7511 if (p is UInt32?) return ToSqlInt16((UInt32?) p); | |
| 7512 if (p is UInt64?) return ToSqlInt16((UInt64?) p); | |
| 7513 } | |
| 7514 | |
| 7515 // Sql Types | |
| 7516 // | |
| 7517 if (p is INullable) | |
| 7518 { | |
| 7519 if (p is SqlBoolean) return ToSqlInt16((SqlBoolean)p); | |
| 7520 if (p is SqlByte) return ToSqlInt16((SqlByte) p); | |
| 7521 if (p is SqlDecimal) return ToSqlInt16((SqlDecimal)p); | |
| 7522 if (p is SqlDouble) return ToSqlInt16((SqlDouble) p); | |
| 7523 if (p is SqlInt32) return ToSqlInt16((SqlInt32) p); | |
| 7524 if (p is SqlInt64) return ToSqlInt16((SqlInt64) p); | |
| 7525 if (p is SqlMoney) return ToSqlInt16((SqlMoney) p); | |
| 7526 if (p is SqlSingle) return ToSqlInt16((SqlSingle) p); | |
| 7527 if (p is SqlString) return ToSqlInt16((SqlString) p); | |
| 7528 } | |
| 7529 | |
| 7530 // Other Types | |
| 7531 // | |
| 7532 if (p is Binary) return ToSqlInt16((Binary) p); | |
| 7533 if (p is Byte[]) return ToSqlInt16((Byte[]) p); | |
| 7534 | |
| 7535 throw CreateInvalidCastException(p.GetType(), typeof(SqlInt16)); | |
| 7536 } | |
| 7537 | |
| 7538 #endif | |
| 7539 | |
| 7540 #endregion | |
| 7541 | |
| 7542 #region SqlInt32 | |
| 7543 | |
| 7544 #if !SILVERLIGHT | |
| 7545 | |
| 7546 // Simple Types | |
| 7547 // | |
| 7548 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7549 public static SqlInt32 ToSqlInt32(Boolean p) { return p ? (SqlInt32)1 : (SqlInt32)0; } | |
| 7550 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7551 public static SqlInt32 ToSqlInt32(Byte p) { return p; } | |
| 7552 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7553 public static SqlInt32 ToSqlInt32(Char p) { return p; } | |
| 7554 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7555 public static SqlInt32 ToSqlInt32(Decimal p) { return checked((Int32)p); } | |
| 7556 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7557 public static SqlInt32 ToSqlInt32(Double p) { return checked((Int32)p); } | |
| 7558 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7559 public static SqlInt32 ToSqlInt32(Int16 p) { return p; } | |
| 7560 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7561 public static SqlInt32 ToSqlInt32(Int32 p) { return p; } | |
| 7562 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7563 public static SqlInt32 ToSqlInt32(Int64 p) { return checked((Int32)p); } | |
| 7564 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7565 [CLSCompliant(false)] | |
| 7566 public static SqlInt32 ToSqlInt32(SByte p) { return p; } | |
| 7567 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7568 public static SqlInt32 ToSqlInt32(Single p) { return checked((Int32)p); } | |
| 7569 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7570 public static SqlInt32 ToSqlInt32(String p) { return p == null? SqlInt32.Null : Int32.Parse(p); } | |
| 7571 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7572 [CLSCompliant(false)] | |
| 7573 public static SqlInt32 ToSqlInt32(UInt16 p) { return p; } | |
| 7574 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7575 [CLSCompliant(false)] | |
| 7576 public static SqlInt32 ToSqlInt32(UInt32 p) { return checked((Int32)p); } | |
| 7577 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7578 [CLSCompliant(false)] | |
| 7579 public static SqlInt32 ToSqlInt32(UInt64 p) { return checked((Int32)p); } | |
| 7580 | |
| 7581 // Nullable Types | |
| 7582 // | |
| 7583 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7584 public static SqlInt32 ToSqlInt32(Boolean? p) { return p.HasValue && p.Value ? (SqlInt32)1: (SqlInt32)0; } | |
| 7585 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7586 public static SqlInt32 ToSqlInt32(Byte? p) { return p.HasValue ? p.Value : SqlInt32.Null; } | |
| 7587 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7588 public static SqlInt32 ToSqlInt32(Char? p) { return p.HasValue ? p.Value : SqlInt32.Null; } | |
| 7589 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7590 public static SqlInt32 ToSqlInt32(Decimal? p) { return p.HasValue ? checked((Int32)p.Value) : SqlInt32.Null; } | |
| 7591 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7592 public static SqlInt32 ToSqlInt32(Double? p) { return p.HasValue ? checked((Int32)p.Value) : SqlInt32.Null; } | |
| 7593 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7594 public static SqlInt32 ToSqlInt32(Int16? p) { return p.HasValue ? p.Value : SqlInt32.Null; } | |
| 7595 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7596 public static SqlInt32 ToSqlInt32(Int32? p) { return p.HasValue ? p.Value : SqlInt32.Null; } | |
| 7597 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7598 public static SqlInt32 ToSqlInt32(Int64? p) { return p.HasValue ? checked((Int32)p.Value) : SqlInt32.Null; } | |
| 7599 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7600 [CLSCompliant(false)] | |
| 7601 public static SqlInt32 ToSqlInt32(SByte? p) { return p.HasValue ? p.Value : SqlInt32.Null; } | |
| 7602 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7603 public static SqlInt32 ToSqlInt32(Single? p) { return p.HasValue ? checked((Int32)p.Value) : SqlInt32.Null; } | |
| 7604 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7605 [CLSCompliant(false)] | |
| 7606 public static SqlInt32 ToSqlInt32(UInt16? p) { return p.HasValue ? p.Value : SqlInt32.Null; } | |
| 7607 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7608 [CLSCompliant(false)] | |
| 7609 public static SqlInt32 ToSqlInt32(UInt32? p) { return p.HasValue ? checked((Int32)p.Value) : SqlInt32.Null; } | |
| 7610 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7611 [CLSCompliant(false)] | |
| 7612 public static SqlInt32 ToSqlInt32(UInt64? p) { return p.HasValue ? checked((Int32)p.Value) : SqlInt32.Null; } | |
| 7613 | |
| 7614 // Sql Types | |
| 7615 // | |
| 7616 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7617 public static SqlInt32 ToSqlInt32(SqlBoolean p) { return p.ToSqlInt32(); } | |
| 7618 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7619 public static SqlInt32 ToSqlInt32(SqlByte p) { return p.ToSqlInt32(); } | |
| 7620 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7621 public static SqlInt32 ToSqlInt32(SqlDecimal p) { return p.ToSqlInt32(); } | |
| 7622 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7623 public static SqlInt32 ToSqlInt32(SqlDouble p) { return p.ToSqlInt32(); } | |
| 7624 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7625 public static SqlInt32 ToSqlInt32(SqlInt16 p) { return p.ToSqlInt32(); } | |
| 7626 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7627 public static SqlInt32 ToSqlInt32(SqlInt64 p) { return p.ToSqlInt32(); } | |
| 7628 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7629 public static SqlInt32 ToSqlInt32(SqlMoney p) { return p.ToSqlInt32(); } | |
| 7630 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7631 public static SqlInt32 ToSqlInt32(SqlSingle p) { return p.ToSqlInt32(); } | |
| 7632 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7633 public static SqlInt32 ToSqlInt32(SqlString p) { return p.ToSqlInt32(); } | |
| 7634 | |
| 7635 // Other Types | |
| 7636 // | |
| 7637 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7638 public static SqlInt32 ToSqlInt32(Binary p) { return p == null || p.Length == 0 ? SqlInt32.Null : BitConverter.ToInt32(p.ToArray(), 0); } | |
| 7639 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7640 public static SqlInt32 ToSqlInt32(Byte[] p) { return p == null || p.Length == 0 ? SqlInt32.Null : BitConverter.ToInt32(p, 0); } | |
| 7641 | |
| 7642 // From Object | |
| 7643 // | |
| 7644 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlInt32</c> value.</summary> | |
| 7645 public static SqlInt32 ToSqlInt32(object p) | |
| 7646 { | |
| 7647 if (p == null) return SqlInt32.Null; | |
| 7648 | |
| 7649 if (p is SqlInt32) return (SqlInt32)p; | |
| 7650 | |
| 7651 var type = p.GetType(); | |
| 7652 | |
| 7653 // Primitive types | |
| 7654 // | |
| 7655 switch (Type.GetTypeCode(type)) | |
| 7656 { | |
| 7657 case TypeCode.DBNull : return SqlInt32.Null; | |
| 7658 case TypeCode.SByte : return ToSqlInt32((SByte) p); | |
| 7659 case TypeCode.Int16 : return ToSqlInt32((Int16) p); | |
| 7660 case TypeCode.Int32 : return ToSqlInt32((Int32) p); | |
| 7661 case TypeCode.Byte : return ToSqlInt32((Byte) p); | |
| 7662 case TypeCode.UInt16 : return ToSqlInt32((UInt16) p); | |
| 7663 case TypeCode.Char : return ToSqlInt32((Char) p); | |
| 7664 case TypeCode.Int64 : return ToSqlInt32((Int64) p); | |
| 7665 case TypeCode.UInt32 : return ToSqlInt32((UInt32) p); | |
| 7666 case TypeCode.UInt64 : return ToSqlInt32((UInt64) p); | |
| 7667 case TypeCode.Single : return ToSqlInt32((Single) p); | |
| 7668 case TypeCode.Double : return ToSqlInt32((Double) p); | |
| 7669 case TypeCode.Decimal : return ToSqlInt32((Decimal) p); | |
| 7670 case TypeCode.String : return ToSqlInt32((String) p); | |
| 7671 case TypeCode.Boolean : return ToSqlInt32((Boolean) p); | |
| 7672 } | |
| 7673 | |
| 7674 // Nullable Types | |
| 7675 // | |
| 7676 if (type.IsGenericType) | |
| 7677 { | |
| 7678 if (p is Boolean?) return ToSqlInt32((Boolean?) p); | |
| 7679 if (p is Byte?) return ToSqlInt32((Byte?) p); | |
| 7680 if (p is Char?) return ToSqlInt32((Char?) p); | |
| 7681 if (p is Decimal?) return ToSqlInt32((Decimal?) p); | |
| 7682 if (p is Double?) return ToSqlInt32((Double?) p); | |
| 7683 if (p is Int16?) return ToSqlInt32((Int16?) p); | |
| 7684 if (p is Int32?) return ToSqlInt32((Int32?) p); | |
| 7685 if (p is Int64?) return ToSqlInt32((Int64?) p); | |
| 7686 if (p is SByte?) return ToSqlInt32((SByte?) p); | |
| 7687 if (p is Single?) return ToSqlInt32((Single?) p); | |
| 7688 if (p is UInt16?) return ToSqlInt32((UInt16?) p); | |
| 7689 if (p is UInt32?) return ToSqlInt32((UInt32?) p); | |
| 7690 if (p is UInt64?) return ToSqlInt32((UInt64?) p); | |
| 7691 } | |
| 7692 | |
| 7693 // Sql Types | |
| 7694 // | |
| 7695 if (p is INullable) | |
| 7696 { | |
| 7697 if (p is SqlBoolean) return ToSqlInt32((SqlBoolean)p); | |
| 7698 if (p is SqlByte) return ToSqlInt32((SqlByte) p); | |
| 7699 if (p is SqlDecimal) return ToSqlInt32((SqlDecimal)p); | |
| 7700 if (p is SqlDouble) return ToSqlInt32((SqlDouble) p); | |
| 7701 if (p is SqlInt16) return ToSqlInt32((SqlInt16) p); | |
| 7702 if (p is SqlInt64) return ToSqlInt32((SqlInt64) p); | |
| 7703 if (p is SqlMoney) return ToSqlInt32((SqlMoney) p); | |
| 7704 if (p is SqlSingle) return ToSqlInt32((SqlSingle) p); | |
| 7705 if (p is SqlString) return ToSqlInt32((SqlString) p); | |
| 7706 } | |
| 7707 | |
| 7708 // Other Types | |
| 7709 // | |
| 7710 if (p is Binary) return ToSqlInt32((Binary) p); | |
| 7711 if (p is Byte[]) return ToSqlInt32((Byte[]) p); | |
| 7712 | |
| 7713 throw CreateInvalidCastException(p.GetType(), typeof(SqlInt32)); | |
| 7714 } | |
| 7715 | |
| 7716 #endif | |
| 7717 | |
| 7718 #endregion | |
| 7719 | |
| 7720 #region SqlInt64 | |
| 7721 | |
| 7722 #if !SILVERLIGHT | |
| 7723 | |
| 7724 // Simple Types | |
| 7725 // | |
| 7726 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7727 public static SqlInt64 ToSqlInt64(Boolean p) { return p ? (SqlInt64)1 : (SqlInt64)0; } | |
| 7728 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7729 public static SqlInt64 ToSqlInt64(Byte p) { return p; } | |
| 7730 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7731 public static SqlInt64 ToSqlInt64(Char p) { return p; } | |
| 7732 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7733 public static SqlInt64 ToSqlInt64(DateTime p) { return (p - DateTime.MinValue).Ticks; } | |
| 7734 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7735 public static SqlInt64 ToSqlInt64(DateTimeOffset p) { return (p - DateTime.MinValue).Ticks; } | |
| 7736 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7737 public static SqlInt64 ToSqlInt64(Decimal p) { return checked((Int64)p); } | |
| 7738 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7739 public static SqlInt64 ToSqlInt64(Double p) { return checked((Int64)p); } | |
| 7740 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7741 public static SqlInt64 ToSqlInt64(Int16 p) { return p; } | |
| 7742 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7743 public static SqlInt64 ToSqlInt64(Int32 p) { return p; } | |
| 7744 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7745 public static SqlInt64 ToSqlInt64(Int64 p) { return p; } | |
| 7746 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7747 [CLSCompliant(false)] | |
| 7748 public static SqlInt64 ToSqlInt64(SByte p) { return p; } | |
| 7749 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7750 public static SqlInt64 ToSqlInt64(Single p) { return checked((Int64)p); } | |
| 7751 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7752 public static SqlInt64 ToSqlInt64(String p) { return p == null? SqlInt64.Null : Int64.Parse(p); } | |
| 7753 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7754 public static SqlInt64 ToSqlInt64(TimeSpan p) { return p.Ticks; } | |
| 7755 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7756 [CLSCompliant(false)] | |
| 7757 public static SqlInt64 ToSqlInt64(UInt16 p) { return p; } | |
| 7758 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7759 [CLSCompliant(false)] | |
| 7760 public static SqlInt64 ToSqlInt64(UInt32 p) { return p; } | |
| 7761 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7762 [CLSCompliant(false)] | |
| 7763 public static SqlInt64 ToSqlInt64(UInt64 p) { return checked((Int64)p); } | |
| 7764 | |
| 7765 // Nullable Types | |
| 7766 // | |
| 7767 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7768 public static SqlInt64 ToSqlInt64(Boolean? p) { return p.HasValue && p.Value ? (SqlInt64)1: (SqlInt64)0; } | |
| 7769 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7770 public static SqlInt64 ToSqlInt64(Byte? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7771 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7772 public static SqlInt64 ToSqlInt64(Char? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7773 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7774 public static SqlInt64 ToSqlInt64(DateTime? p) { return p.HasValue ? (p.Value - DateTime.MinValue).Ticks : 0; } | |
| 7775 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7776 public static SqlInt64 ToSqlInt64(DateTimeOffset? p) { return p.HasValue ? (p.Value - DateTime.MinValue).Ticks : 0; } | |
| 7777 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7778 public static SqlInt64 ToSqlInt64(Decimal? p) { return p.HasValue ? checked((Int64)p.Value) : SqlInt64.Null; } | |
| 7779 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7780 public static SqlInt64 ToSqlInt64(Double? p) { return p.HasValue ? checked((Int64)p.Value) : SqlInt64.Null; } | |
| 7781 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7782 public static SqlInt64 ToSqlInt64(Int16? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7783 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7784 public static SqlInt64 ToSqlInt64(Int32? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7785 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7786 public static SqlInt64 ToSqlInt64(Int64? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7787 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7788 [CLSCompliant(false)] | |
| 7789 public static SqlInt64 ToSqlInt64(SByte? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7790 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7791 public static SqlInt64 ToSqlInt64(Single? p) { return p.HasValue ? checked((Int64)p.Value) : SqlInt64.Null; } | |
| 7792 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7793 public static SqlInt64 ToSqlInt64(TimeSpan? p) { return p.HasValue ? p.Value.Ticks : 0; } | |
| 7794 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7795 [CLSCompliant(false)] | |
| 7796 public static SqlInt64 ToSqlInt64(UInt16? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7797 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7798 [CLSCompliant(false)] | |
| 7799 public static SqlInt64 ToSqlInt64(UInt32? p) { return p.HasValue ? p.Value : SqlInt64.Null; } | |
| 7800 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7801 [CLSCompliant(false)] | |
| 7802 public static SqlInt64 ToSqlInt64(UInt64? p) { return p.HasValue ? checked((Int64)p.Value) : SqlInt64.Null; } | |
| 7803 | |
| 7804 // Sql Types | |
| 7805 // | |
| 7806 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7807 public static SqlInt64 ToSqlInt64(SqlBoolean p) { return p.ToSqlInt64(); } | |
| 7808 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7809 public static SqlInt64 ToSqlInt64(SqlByte p) { return p.ToSqlInt64(); } | |
| 7810 /// <summary>Converts the value from <c>SqlDateTime</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7811 public static SqlInt64 ToSqlInt64(SqlDateTime p) { return p.IsNull? SqlInt64.Null: ToInt64(p.Value); } | |
| 7812 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7813 public static SqlInt64 ToSqlInt64(SqlDecimal p) { return p.ToSqlInt64(); } | |
| 7814 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7815 public static SqlInt64 ToSqlInt64(SqlDouble p) { return p.ToSqlInt64(); } | |
| 7816 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7817 public static SqlInt64 ToSqlInt64(SqlInt16 p) { return p.ToSqlInt64(); } | |
| 7818 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7819 public static SqlInt64 ToSqlInt64(SqlInt32 p) { return p.ToSqlInt64(); } | |
| 7820 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7821 public static SqlInt64 ToSqlInt64(SqlMoney p) { return p.ToSqlInt64(); } | |
| 7822 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7823 public static SqlInt64 ToSqlInt64(SqlSingle p) { return p.ToSqlInt64(); } | |
| 7824 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7825 public static SqlInt64 ToSqlInt64(SqlString p) { return p.ToSqlInt64(); } | |
| 7826 | |
| 7827 // Other Types | |
| 7828 // | |
| 7829 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7830 public static SqlInt64 ToSqlInt64(Binary p) { return p == null || p.Length == 0 ? SqlInt64.Null : BitConverter.ToInt64(p.ToArray(), 0); } | |
| 7831 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7832 public static SqlInt64 ToSqlInt64(Byte[] p) { return p == null || p.Length == 0 ? SqlInt64.Null : BitConverter.ToInt64(p, 0); } | |
| 7833 | |
| 7834 // From Object | |
| 7835 // | |
| 7836 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlInt64</c> value.</summary> | |
| 7837 public static SqlInt64 ToSqlInt64(object p) | |
| 7838 { | |
| 7839 if (p == null) return SqlInt64.Null; | |
| 7840 | |
| 7841 if (p is SqlInt64) return (SqlInt64)p; | |
| 7842 | |
| 7843 var type = p.GetType(); | |
| 7844 | |
| 7845 // Primitive types | |
| 7846 // | |
| 7847 switch (Type.GetTypeCode(type)) | |
| 7848 { | |
| 7849 case TypeCode.DBNull : return SqlInt64.Null; | |
| 7850 case TypeCode.DateTime : return ToSqlInt64((DateTime)p); | |
| 7851 case TypeCode.SByte : return ToSqlInt64((SByte) p); | |
| 7852 case TypeCode.Int16 : return ToSqlInt64((Int16) p); | |
| 7853 case TypeCode.Int32 : return ToSqlInt64((Int32) p); | |
| 7854 case TypeCode.Int64 : return ToSqlInt64((Int64) p); | |
| 7855 case TypeCode.Byte : return ToSqlInt64((Byte) p); | |
| 7856 case TypeCode.UInt16 : return ToSqlInt64((UInt16) p); | |
| 7857 case TypeCode.UInt32 : return ToSqlInt64((UInt32) p); | |
| 7858 case TypeCode.Char : return ToSqlInt64((Char) p); | |
| 7859 case TypeCode.UInt64 : return ToSqlInt64((UInt64) p); | |
| 7860 case TypeCode.Single : return ToSqlInt64((Single) p); | |
| 7861 case TypeCode.Double : return ToSqlInt64((Double) p); | |
| 7862 case TypeCode.Decimal : return ToSqlInt64((Decimal) p); | |
| 7863 case TypeCode.String : return ToSqlInt64((String) p); | |
| 7864 case TypeCode.Boolean : return ToSqlInt64((Boolean) p); | |
| 7865 } | |
| 7866 | |
| 7867 // Simple Types | |
| 7868 // | |
| 7869 if (p is DateTimeOffset) return ToSqlInt64((DateTimeOffset) p); | |
| 7870 if (p is TimeSpan) return ToSqlInt64((TimeSpan) p); | |
| 7871 | |
| 7872 // Nullable Types | |
| 7873 // | |
| 7874 if (type.IsGenericType) | |
| 7875 { | |
| 7876 if (p is Boolean?) return ToSqlInt64((Boolean?) p); | |
| 7877 if (p is Byte?) return ToSqlInt64((Byte?) p); | |
| 7878 if (p is Char?) return ToSqlInt64((Char?) p); | |
| 7879 if (p is DateTime?) return ToSqlInt64((DateTime?) p); | |
| 7880 if (p is DateTimeOffset?) return ToSqlInt64((DateTimeOffset?)p); | |
| 7881 if (p is Decimal?) return ToSqlInt64((Decimal?) p); | |
| 7882 if (p is Double?) return ToSqlInt64((Double?) p); | |
| 7883 if (p is Int16?) return ToSqlInt64((Int16?) p); | |
| 7884 if (p is Int32?) return ToSqlInt64((Int32?) p); | |
| 7885 if (p is Int64?) return ToSqlInt64((Int64?) p); | |
| 7886 if (p is SByte?) return ToSqlInt64((SByte?) p); | |
| 7887 if (p is Single?) return ToSqlInt64((Single?) p); | |
| 7888 if (p is TimeSpan?) return ToSqlInt64((TimeSpan?) p); | |
| 7889 if (p is UInt16?) return ToSqlInt64((UInt16?) p); | |
| 7890 if (p is UInt32?) return ToSqlInt64((UInt32?) p); | |
| 7891 if (p is UInt64?) return ToSqlInt64((UInt64?) p); | |
| 7892 } | |
| 7893 | |
| 7894 // Sql Types | |
| 7895 // | |
| 7896 if (p is INullable) | |
| 7897 { | |
| 7898 if (p is SqlBoolean) return ToSqlInt64((SqlBoolean) p); | |
| 7899 if (p is SqlByte) return ToSqlInt64((SqlByte) p); | |
| 7900 if (p is SqlDateTime) return ToSqlInt64((SqlDateTime) p); | |
| 7901 if (p is SqlDecimal) return ToSqlInt64((SqlDecimal) p); | |
| 7902 if (p is SqlDouble) return ToSqlInt64((SqlDouble) p); | |
| 7903 if (p is SqlInt16) return ToSqlInt64((SqlInt16) p); | |
| 7904 if (p is SqlInt32) return ToSqlInt64((SqlInt32) p); | |
| 7905 if (p is SqlMoney) return ToSqlInt64((SqlMoney) p); | |
| 7906 if (p is SqlSingle) return ToSqlInt64((SqlSingle) p); | |
| 7907 if (p is SqlString) return ToSqlInt64((SqlString) p); | |
| 7908 } | |
| 7909 | |
| 7910 // Other Types | |
| 7911 // | |
| 7912 if (p is Binary) return ToSqlInt64((Binary) p); | |
| 7913 if (p is Byte[]) return ToSqlInt64((Byte[]) p); | |
| 7914 | |
| 7915 throw CreateInvalidCastException(p.GetType(), typeof(SqlInt64)); | |
| 7916 } | |
| 7917 | |
| 7918 #endif | |
| 7919 | |
| 7920 #endregion | |
| 7921 | |
| 7922 #region SqlMoney | |
| 7923 | |
| 7924 #if !SILVERLIGHT | |
| 7925 | |
| 7926 // Simple Types | |
| 7927 // | |
| 7928 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7929 public static SqlMoney ToSqlMoney(Boolean p) { return p ? (SqlMoney)1 : (SqlMoney)0; } | |
| 7930 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7931 public static SqlMoney ToSqlMoney(Byte p) { return p; } | |
| 7932 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7933 public static SqlMoney ToSqlMoney(Char p) { return p; } | |
| 7934 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7935 public static SqlMoney ToSqlMoney(Decimal p) { return p; } | |
| 7936 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7937 public static SqlMoney ToSqlMoney(Double p) { return checked((Decimal)p); } | |
| 7938 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7939 public static SqlMoney ToSqlMoney(Int16 p) { return p; } | |
| 7940 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7941 public static SqlMoney ToSqlMoney(Int32 p) { return p; } | |
| 7942 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7943 public static SqlMoney ToSqlMoney(Int64 p) { return p; } | |
| 7944 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7945 [CLSCompliant(false)] | |
| 7946 public static SqlMoney ToSqlMoney(SByte p) { return p; } | |
| 7947 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7948 public static SqlMoney ToSqlMoney(Single p) { return checked((Decimal)p); } | |
| 7949 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7950 public static SqlMoney ToSqlMoney(String p) { return p == null? SqlMoney.Null : Decimal.Parse(p); } | |
| 7951 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7952 [CLSCompliant(false)] | |
| 7953 public static SqlMoney ToSqlMoney(UInt16 p) { return p; } | |
| 7954 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7955 [CLSCompliant(false)] | |
| 7956 public static SqlMoney ToSqlMoney(UInt32 p) { return p; } | |
| 7957 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7958 [CLSCompliant(false)] | |
| 7959 public static SqlMoney ToSqlMoney(UInt64 p) { return p; } | |
| 7960 | |
| 7961 // Nullable Types | |
| 7962 // | |
| 7963 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7964 public static SqlMoney ToSqlMoney(Boolean? p) { return p.HasValue && p.Value ? (SqlMoney)1: (SqlMoney)0; } | |
| 7965 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7966 public static SqlMoney ToSqlMoney(Byte? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7967 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7968 public static SqlMoney ToSqlMoney(Char? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7969 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7970 public static SqlMoney ToSqlMoney(Decimal? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7971 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7972 public static SqlMoney ToSqlMoney(Double? p) { return p.HasValue ? checked((Decimal)p.Value) : SqlMoney.Null; } | |
| 7973 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7974 public static SqlMoney ToSqlMoney(Int16? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7975 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7976 public static SqlMoney ToSqlMoney(Int32? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7977 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7978 public static SqlMoney ToSqlMoney(Int64? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7979 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7980 [CLSCompliant(false)] | |
| 7981 public static SqlMoney ToSqlMoney(SByte? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7982 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7983 public static SqlMoney ToSqlMoney(Single? p) { return p.HasValue ? checked((Decimal)p.Value) : SqlMoney.Null; } | |
| 7984 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7985 [CLSCompliant(false)] | |
| 7986 public static SqlMoney ToSqlMoney(UInt16? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7987 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7988 [CLSCompliant(false)] | |
| 7989 public static SqlMoney ToSqlMoney(UInt32? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7990 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7991 [CLSCompliant(false)] | |
| 7992 public static SqlMoney ToSqlMoney(UInt64? p) { return p.HasValue ? p.Value : SqlMoney.Null; } | |
| 7993 | |
| 7994 // Sql Types | |
| 7995 // | |
| 7996 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7997 public static SqlMoney ToSqlMoney(SqlBoolean p) { return p.ToSqlMoney(); } | |
| 7998 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 7999 public static SqlMoney ToSqlMoney(SqlByte p) { return p.ToSqlMoney(); } | |
| 8000 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8001 public static SqlMoney ToSqlMoney(SqlDecimal p) { return p.ToSqlMoney(); } | |
| 8002 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8003 public static SqlMoney ToSqlMoney(SqlDouble p) { return p.ToSqlMoney(); } | |
| 8004 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8005 public static SqlMoney ToSqlMoney(SqlInt16 p) { return p.ToSqlMoney(); } | |
| 8006 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8007 public static SqlMoney ToSqlMoney(SqlInt32 p) { return p.ToSqlMoney(); } | |
| 8008 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8009 public static SqlMoney ToSqlMoney(SqlInt64 p) { return p.ToSqlMoney(); } | |
| 8010 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8011 public static SqlMoney ToSqlMoney(SqlSingle p) { return p.ToSqlMoney(); } | |
| 8012 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8013 public static SqlMoney ToSqlMoney(SqlString p) { return p.ToSqlMoney(); } | |
| 8014 | |
| 8015 // Other Types | |
| 8016 // | |
| 8017 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8018 public static SqlMoney ToSqlMoney(Binary p) { return p == null || p.Length == 0 ? SqlMoney.Null : ToDecimal(p); } | |
| 8019 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8020 public static SqlMoney ToSqlMoney(Byte[] p) { return p == null || p.Length == 0 ? SqlMoney.Null : ToDecimal(p); } | |
| 8021 | |
| 8022 // From Object | |
| 8023 // | |
| 8024 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlMoney</c> value.</summary> | |
| 8025 public static SqlMoney ToSqlMoney(object p) | |
| 8026 { | |
| 8027 if (p == null) return SqlMoney.Null; | |
| 8028 | |
| 8029 if (p is SqlMoney) return (SqlMoney)p; | |
| 8030 | |
| 8031 var type = p.GetType(); | |
| 8032 | |
| 8033 // Primitive types | |
| 8034 // | |
| 8035 switch (Type.GetTypeCode(type)) | |
| 8036 { | |
| 8037 case TypeCode.DBNull : return SqlMoney.Null; | |
| 8038 case TypeCode.SByte : return ToSqlMoney((SByte) p); | |
| 8039 case TypeCode.Int16 : return ToSqlMoney((Int16) p); | |
| 8040 case TypeCode.Int32 : return ToSqlMoney((Int32) p); | |
| 8041 case TypeCode.Int64 : return ToSqlMoney((Int64) p); | |
| 8042 case TypeCode.Byte : return ToSqlMoney((Byte) p); | |
| 8043 case TypeCode.UInt16 : return ToSqlMoney((UInt16) p); | |
| 8044 case TypeCode.UInt32 : return ToSqlMoney((UInt32) p); | |
| 8045 case TypeCode.Char : return ToSqlMoney((Char) p); | |
| 8046 case TypeCode.UInt64 : return ToSqlMoney((UInt64) p); | |
| 8047 case TypeCode.Decimal : return ToSqlMoney((Decimal) p); | |
| 8048 case TypeCode.Single : return ToSqlMoney((Single) p); | |
| 8049 case TypeCode.Double : return ToSqlMoney((Double) p); | |
| 8050 case TypeCode.String : return ToSqlMoney((String) p); | |
| 8051 case TypeCode.Boolean : return ToSqlMoney((Boolean) p); | |
| 8052 } | |
| 8053 | |
| 8054 // Nullable Types | |
| 8055 // | |
| 8056 if (type.IsGenericType) | |
| 8057 { | |
| 8058 if (p is Boolean?) return ToSqlMoney((Boolean?) p); | |
| 8059 if (p is Byte?) return ToSqlMoney((Byte?) p); | |
| 8060 if (p is Char?) return ToSqlMoney((Char?) p); | |
| 8061 if (p is Decimal?) return ToSqlMoney((Decimal?) p); | |
| 8062 if (p is Double?) return ToSqlMoney((Double?) p); | |
| 8063 if (p is Int16?) return ToSqlMoney((Int16?) p); | |
| 8064 if (p is Int32?) return ToSqlMoney((Int32?) p); | |
| 8065 if (p is Int64?) return ToSqlMoney((Int64?) p); | |
| 8066 if (p is SByte?) return ToSqlMoney((SByte?) p); | |
| 8067 if (p is Single?) return ToSqlMoney((Single?) p); | |
| 8068 if (p is UInt16?) return ToSqlMoney((UInt16?) p); | |
| 8069 if (p is UInt32?) return ToSqlMoney((UInt32?) p); | |
| 8070 if (p is UInt64?) return ToSqlMoney((UInt64?) p); | |
| 8071 } | |
| 8072 | |
| 8073 // Sql Types | |
| 8074 // | |
| 8075 if (p is INullable) | |
| 8076 { | |
| 8077 if (p is SqlBoolean) return ToSqlMoney((SqlBoolean)p); | |
| 8078 if (p is SqlByte) return ToSqlMoney((SqlByte) p); | |
| 8079 if (p is SqlDecimal) return ToSqlMoney((SqlDecimal)p); | |
| 8080 if (p is SqlDouble) return ToSqlMoney((SqlDouble) p); | |
| 8081 if (p is SqlInt16) return ToSqlMoney((SqlInt16) p); | |
| 8082 if (p is SqlInt32) return ToSqlMoney((SqlInt32) p); | |
| 8083 if (p is SqlInt64) return ToSqlMoney((SqlInt64) p); | |
| 8084 if (p is SqlSingle) return ToSqlMoney((SqlSingle) p); | |
| 8085 if (p is SqlString) return ToSqlMoney((SqlString) p); | |
| 8086 } | |
| 8087 | |
| 8088 // Other Types | |
| 8089 // | |
| 8090 if (p is Binary) return ToSqlMoney((Binary) p); | |
| 8091 if (p is Byte[]) return ToSqlMoney((Byte[]) p); | |
| 8092 | |
| 8093 throw CreateInvalidCastException(p.GetType(), typeof(SqlMoney)); | |
| 8094 } | |
| 8095 | |
| 8096 #endif | |
| 8097 | |
| 8098 #endregion | |
| 8099 | |
| 8100 #region SqlSingle | |
| 8101 | |
| 8102 #if !SILVERLIGHT | |
| 8103 | |
| 8104 // Simple Types | |
| 8105 // | |
| 8106 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8107 public static SqlSingle ToSqlSingle(Boolean p) { return p ? (SqlSingle)1 : (SqlSingle)0; } | |
| 8108 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8109 public static SqlSingle ToSqlSingle(Byte p) { return p; } | |
| 8110 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8111 public static SqlSingle ToSqlSingle(Char p) { return p; } | |
| 8112 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8113 public static SqlSingle ToSqlSingle(Decimal p) { return checked((Single)p); } | |
| 8114 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8115 public static SqlSingle ToSqlSingle(Double p) { return checked((Single)p); } | |
| 8116 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8117 public static SqlSingle ToSqlSingle(Int16 p) { return p; } | |
| 8118 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8119 public static SqlSingle ToSqlSingle(Int32 p) { return p; } | |
| 8120 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8121 public static SqlSingle ToSqlSingle(Int64 p) { return p; } | |
| 8122 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8123 [CLSCompliant(false)] | |
| 8124 public static SqlSingle ToSqlSingle(SByte p) { return p; } | |
| 8125 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8126 public static SqlSingle ToSqlSingle(Single p) { return p; } | |
| 8127 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8128 public static SqlSingle ToSqlSingle(String p) { return p == null? SqlSingle.Null : Single.Parse(p); } | |
| 8129 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8130 [CLSCompliant(false)] | |
| 8131 public static SqlSingle ToSqlSingle(UInt16 p) { return p; } | |
| 8132 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8133 [CLSCompliant(false)] | |
| 8134 public static SqlSingle ToSqlSingle(UInt32 p) { return p; } | |
| 8135 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8136 [CLSCompliant(false)] | |
| 8137 public static SqlSingle ToSqlSingle(UInt64 p) { return p; } | |
| 8138 | |
| 8139 // Nullable Types | |
| 8140 // | |
| 8141 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8142 public static SqlSingle ToSqlSingle(Boolean? p) { return p.HasValue && p.Value ? (SqlSingle)1: (SqlSingle)0; } | |
| 8143 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8144 public static SqlSingle ToSqlSingle(Byte? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8145 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8146 public static SqlSingle ToSqlSingle(Char? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8147 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8148 public static SqlSingle ToSqlSingle(Decimal? p) { return p.HasValue ? checked((Single)p.Value) : SqlSingle.Null; } | |
| 8149 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8150 public static SqlSingle ToSqlSingle(Double? p) { return p.HasValue ? checked((Single)p.Value) : SqlSingle.Null; } | |
| 8151 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8152 public static SqlSingle ToSqlSingle(Int16? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8153 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8154 public static SqlSingle ToSqlSingle(Int32? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8155 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8156 public static SqlSingle ToSqlSingle(Int64? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8157 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8158 [CLSCompliant(false)] | |
| 8159 public static SqlSingle ToSqlSingle(SByte? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8160 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8161 public static SqlSingle ToSqlSingle(Single? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8162 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8163 [CLSCompliant(false)] | |
| 8164 public static SqlSingle ToSqlSingle(UInt16? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8165 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8166 [CLSCompliant(false)] | |
| 8167 public static SqlSingle ToSqlSingle(UInt32? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8168 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8169 [CLSCompliant(false)] | |
| 8170 public static SqlSingle ToSqlSingle(UInt64? p) { return p.HasValue ? p.Value : SqlSingle.Null; } | |
| 8171 | |
| 8172 // Sql Types | |
| 8173 // | |
| 8174 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8175 public static SqlSingle ToSqlSingle(SqlBoolean p) { return p.ToSqlSingle(); } | |
| 8176 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8177 public static SqlSingle ToSqlSingle(SqlByte p) { return p.ToSqlSingle(); } | |
| 8178 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8179 public static SqlSingle ToSqlSingle(SqlDecimal p) { return p.ToSqlSingle(); } | |
| 8180 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8181 public static SqlSingle ToSqlSingle(SqlDouble p) { return p.ToSqlSingle(); } | |
| 8182 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8183 public static SqlSingle ToSqlSingle(SqlInt16 p) { return p.ToSqlSingle(); } | |
| 8184 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8185 public static SqlSingle ToSqlSingle(SqlInt32 p) { return p.ToSqlSingle(); } | |
| 8186 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8187 public static SqlSingle ToSqlSingle(SqlInt64 p) { return p.ToSqlSingle(); } | |
| 8188 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8189 public static SqlSingle ToSqlSingle(SqlMoney p) { return p.ToSqlSingle(); } | |
| 8190 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8191 public static SqlSingle ToSqlSingle(SqlString p) { return p.ToSqlSingle(); } | |
| 8192 | |
| 8193 // Other Types | |
| 8194 // | |
| 8195 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8196 public static SqlSingle ToSqlSingle(Binary p) { return p == null || p.Length == 0 ? SqlSingle.Null : BitConverter.ToSingle(p.ToArray(), 0); } | |
| 8197 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8198 public static SqlSingle ToSqlSingle(Byte[] p) { return p == null || p.Length == 0 ? SqlSingle.Null : BitConverter.ToSingle(p, 0); } | |
| 8199 | |
| 8200 // From Object | |
| 8201 // | |
| 8202 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlSingle</c> value.</summary> | |
| 8203 public static SqlSingle ToSqlSingle(object p) | |
| 8204 { | |
| 8205 if (p == null) return SqlSingle.Null; | |
| 8206 | |
| 8207 if (p is SqlSingle) return (SqlSingle)p; | |
| 8208 | |
| 8209 var type = p.GetType(); | |
| 8210 | |
| 8211 // Primitive types | |
| 8212 // | |
| 8213 switch (Type.GetTypeCode(type)) | |
| 8214 { | |
| 8215 case TypeCode.DBNull : return SqlSingle.Null; | |
| 8216 case TypeCode.SByte : return ToSqlSingle((SByte) p); | |
| 8217 case TypeCode.Int16 : return ToSqlSingle((Int16) p); | |
| 8218 case TypeCode.Int32 : return ToSqlSingle((Int32) p); | |
| 8219 case TypeCode.Int64 : return ToSqlSingle((Int64) p); | |
| 8220 case TypeCode.Byte : return ToSqlSingle((Byte) p); | |
| 8221 case TypeCode.UInt16 : return ToSqlSingle((UInt16) p); | |
| 8222 case TypeCode.UInt32 : return ToSqlSingle((UInt32) p); | |
| 8223 case TypeCode.Char : return ToSqlSingle((Char) p); | |
| 8224 case TypeCode.UInt64 : return ToSqlSingle((UInt64) p); | |
| 8225 case TypeCode.Single : return ToSqlSingle((Single) p); | |
| 8226 case TypeCode.Double : return ToSqlSingle((Double) p); | |
| 8227 case TypeCode.Decimal : return ToSqlSingle((Decimal) p); | |
| 8228 case TypeCode.String : return ToSqlSingle((String) p); | |
| 8229 case TypeCode.Boolean : return ToSqlSingle((Boolean) p); | |
| 8230 } | |
| 8231 | |
| 8232 // Nullable Types | |
| 8233 // | |
| 8234 if (type.IsGenericType) | |
| 8235 { | |
| 8236 if (p is Boolean?) return ToSqlSingle((Boolean?) p); | |
| 8237 if (p is Byte?) return ToSqlSingle((Byte?) p); | |
| 8238 if (p is Char?) return ToSqlSingle((Char?) p); | |
| 8239 if (p is Decimal?) return ToSqlSingle((Decimal?) p); | |
| 8240 if (p is Double?) return ToSqlSingle((Double?) p); | |
| 8241 if (p is Int16?) return ToSqlSingle((Int16?) p); | |
| 8242 if (p is Int32?) return ToSqlSingle((Int32?) p); | |
| 8243 if (p is Int64?) return ToSqlSingle((Int64?) p); | |
| 8244 if (p is SByte?) return ToSqlSingle((SByte?) p); | |
| 8245 if (p is Single?) return ToSqlSingle((Single?) p); | |
| 8246 if (p is UInt16?) return ToSqlSingle((UInt16?) p); | |
| 8247 if (p is UInt32?) return ToSqlSingle((UInt32?) p); | |
| 8248 if (p is UInt64?) return ToSqlSingle((UInt64?) p); | |
| 8249 } | |
| 8250 | |
| 8251 // Sql Types | |
| 8252 // | |
| 8253 if (p is INullable) | |
| 8254 { | |
| 8255 if (p is SqlBoolean) return ToSqlSingle((SqlBoolean)p); | |
| 8256 if (p is SqlByte) return ToSqlSingle((SqlByte) p); | |
| 8257 if (p is SqlDecimal) return ToSqlSingle((SqlDecimal)p); | |
| 8258 if (p is SqlDouble) return ToSqlSingle((SqlDouble) p); | |
| 8259 if (p is SqlInt16) return ToSqlSingle((SqlInt16) p); | |
| 8260 if (p is SqlInt32) return ToSqlSingle((SqlInt32) p); | |
| 8261 if (p is SqlInt64) return ToSqlSingle((SqlInt64) p); | |
| 8262 if (p is SqlMoney) return ToSqlSingle((SqlMoney) p); | |
| 8263 if (p is SqlString) return ToSqlSingle((SqlString) p); | |
| 8264 } | |
| 8265 | |
| 8266 // Other Types | |
| 8267 // | |
| 8268 if (p is Binary) return ToSqlSingle((Binary) p); | |
| 8269 if (p is Byte[]) return ToSqlSingle((Byte[]) p); | |
| 8270 | |
| 8271 throw CreateInvalidCastException(p.GetType(), typeof(SqlSingle)); | |
| 8272 } | |
| 8273 | |
| 8274 #endif | |
| 8275 | |
| 8276 #endregion | |
| 8277 | |
| 8278 #region SqlString | |
| 8279 | |
| 8280 #if !SILVERLIGHT | |
| 8281 | |
| 8282 // Simple Types | |
| 8283 // | |
| 8284 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8285 public static SqlString ToSqlString(Boolean p) { return p.ToString(); } | |
| 8286 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8287 public static SqlString ToSqlString(Byte p) { return p.ToString(); } | |
| 8288 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8289 public static SqlString ToSqlString(Char p) { return p.ToString(); } | |
| 8290 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8291 public static SqlString ToSqlString(DateTime p) { return p.ToString(); } | |
| 8292 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8293 public static SqlString ToSqlString(DateTimeOffset p) { return p.ToString(); } | |
| 8294 /// <summary>Converts the value from <c>Decimal</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8295 public static SqlString ToSqlString(Decimal p) { return p.ToString(); } | |
| 8296 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8297 public static SqlString ToSqlString(Double p) { return p.ToString(); } | |
| 8298 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8299 public static SqlString ToSqlString(Guid p) { return p.ToString(); } | |
| 8300 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8301 public static SqlString ToSqlString(Int16 p) { return p.ToString(); } | |
| 8302 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8303 public static SqlString ToSqlString(Int32 p) { return p.ToString(); } | |
| 8304 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8305 public static SqlString ToSqlString(Int64 p) { return p.ToString(); } | |
| 8306 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8307 [CLSCompliant(false)] | |
| 8308 public static SqlString ToSqlString(SByte p) { return p.ToString(); } | |
| 8309 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8310 public static SqlString ToSqlString(Single p) { return p.ToString(); } | |
| 8311 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8312 public static SqlString ToSqlString(String p) { return p ?? SqlString.Null; } | |
| 8313 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8314 public static SqlString ToSqlString(TimeSpan p) { return p.ToString(); } | |
| 8315 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8316 [CLSCompliant(false)] | |
| 8317 public static SqlString ToSqlString(UInt16 p) { return p.ToString(); } | |
| 8318 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8319 [CLSCompliant(false)] | |
| 8320 public static SqlString ToSqlString(UInt32 p) { return p.ToString(); } | |
| 8321 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8322 [CLSCompliant(false)] | |
| 8323 public static SqlString ToSqlString(UInt64 p) { return p.ToString(); } | |
| 8324 | |
| 8325 // Nullable Types | |
| 8326 // | |
| 8327 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8328 public static SqlString ToSqlString(Boolean? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8329 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8330 public static SqlString ToSqlString(Byte? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8331 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8332 public static SqlString ToSqlString(Char? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8333 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8334 public static SqlString ToSqlString(DateTime? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8335 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8336 public static SqlString ToSqlString(DateTimeOffset? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8337 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8338 public static SqlString ToSqlString(Decimal? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8339 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8340 public static SqlString ToSqlString(Double? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8341 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8342 public static SqlString ToSqlString(Guid? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8343 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8344 public static SqlString ToSqlString(Int16? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8345 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8346 public static SqlString ToSqlString(Int32? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8347 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8348 public static SqlString ToSqlString(Int64? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8349 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8350 [CLSCompliant(false)] | |
| 8351 public static SqlString ToSqlString(SByte? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8352 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8353 public static SqlString ToSqlString(Single? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8354 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8355 public static SqlString ToSqlString(TimeSpan? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8356 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8357 [CLSCompliant(false)] | |
| 8358 public static SqlString ToSqlString(UInt16? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8359 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8360 [CLSCompliant(false)] | |
| 8361 public static SqlString ToSqlString(UInt32? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8362 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8363 [CLSCompliant(false)] | |
| 8364 public static SqlString ToSqlString(UInt64? p) { return p.HasValue ? p.Value.ToString() : SqlString.Null; } | |
| 8365 | |
| 8366 // Sql Types | |
| 8367 // | |
| 8368 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8369 public static SqlString ToSqlString(SqlBoolean p) { return p.ToSqlString(); } | |
| 8370 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8371 public static SqlString ToSqlString(SqlByte p) { return p.ToSqlString(); } | |
| 8372 /// <summary>Converts the value from <c>SqlChars</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8373 public static SqlString ToSqlString(SqlChars p) { return p.ToSqlString(); } | |
| 8374 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8375 public static SqlString ToSqlString(SqlDecimal p) { return p.ToSqlString(); } | |
| 8376 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8377 public static SqlString ToSqlString(SqlDouble p) { return p.ToSqlString(); } | |
| 8378 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8379 public static SqlString ToSqlString(SqlGuid p) { return p.ToSqlString(); } | |
| 8380 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8381 public static SqlString ToSqlString(SqlInt16 p) { return p.ToSqlString(); } | |
| 8382 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8383 public static SqlString ToSqlString(SqlInt32 p) { return p.ToSqlString(); } | |
| 8384 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8385 public static SqlString ToSqlString(SqlInt64 p) { return p.ToSqlString(); } | |
| 8386 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8387 public static SqlString ToSqlString(SqlMoney p) { return p.ToSqlString(); } | |
| 8388 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8389 public static SqlString ToSqlString(SqlSingle p) { return p.ToSqlString(); } | |
| 8390 /// <summary>Converts the value from <c>SqlXml</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8391 public static SqlString ToSqlString(SqlXml p) { return p.IsNull ? SqlString.Null : p.Value; } | |
| 8392 | |
| 8393 // Other Types | |
| 8394 // | |
| 8395 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8396 public static SqlString ToSqlString(Binary p) { return ToSqlString(p.ToArray()); } | |
| 8397 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8398 public static SqlString ToSqlString(Byte[] p) { return p == null ? SqlString.Null : System.Text.Encoding.UTF8.GetString(p, 0, p.Length); } | |
| 8399 /// <summary>Converts the value from <c>Type</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8400 public static SqlString ToSqlString(Type p) { return p == null ? SqlString.Null : p.FullName; } | |
| 8401 /// <summary>Converts the value from <c>XElement</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8402 public static SqlString ToSqlString(XElement p) { return p == null ? SqlString.Null : p.ToString(); } | |
| 8403 /// <summary>Converts the value from <c>XmlDocument</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8404 public static SqlString ToSqlString(XmlDocument p) { return p == null ? SqlString.Null : p.InnerXml; } | |
| 8405 | |
| 8406 // From Object | |
| 8407 // | |
| 8408 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlString</c> value.</summary> | |
| 8409 public static SqlString ToSqlString(object p) | |
| 8410 { | |
| 8411 if (p == null) return SqlString.Null; | |
| 8412 | |
| 8413 if (p is SqlString) return (SqlString)p; | |
| 8414 | |
| 8415 var type = p.GetType(); | |
| 8416 | |
| 8417 // Primitive types | |
| 8418 // | |
| 8419 switch (Type.GetTypeCode(type)) | |
| 8420 { | |
| 8421 case TypeCode.DBNull : return SqlString.Null; | |
| 8422 case TypeCode.SByte : return ToSqlString((SByte) p); | |
| 8423 case TypeCode.Int16 : return ToSqlString((Int16) p); | |
| 8424 case TypeCode.Int32 : return ToSqlString((Int32) p); | |
| 8425 case TypeCode.Int64 : return ToSqlString((Int64) p); | |
| 8426 case TypeCode.Byte : return ToSqlString((Byte) p); | |
| 8427 case TypeCode.UInt16 : return ToSqlString((UInt16) p); | |
| 8428 case TypeCode.UInt32 : return ToSqlString((UInt32) p); | |
| 8429 case TypeCode.UInt64 : return ToSqlString((UInt64) p); | |
| 8430 case TypeCode.Single : return ToSqlString((Single) p); | |
| 8431 case TypeCode.Double : return ToSqlString((Double) p); | |
| 8432 case TypeCode.Boolean : return ToSqlString((Boolean) p); | |
| 8433 case TypeCode.Decimal : return ToSqlString((Decimal) p); | |
| 8434 case TypeCode.Char : return ToSqlString((Char) p); | |
| 8435 case TypeCode.DateTime : return ToSqlString((DateTime) p); | |
| 8436 case TypeCode.String : return ToSqlString((String) p); | |
| 8437 } | |
| 8438 | |
| 8439 // Simple Types | |
| 8440 // | |
| 8441 if (p is DateTimeOffset) return ToSqlString((DateTimeOffset) p); | |
| 8442 if (p is Guid) return ToSqlString((Guid) p); | |
| 8443 if (p is TimeSpan) return ToSqlString((TimeSpan) p); | |
| 8444 | |
| 8445 // Nullable Types | |
| 8446 // | |
| 8447 if (type.IsGenericType) | |
| 8448 { | |
| 8449 if (p is Boolean?) return ToSqlString((Boolean?) p); | |
| 8450 if (p is Byte?) return ToSqlString((Byte?) p); | |
| 8451 if (p is Char?) return ToSqlString((Char?) p); | |
| 8452 if (p is DateTime?) return ToSqlString((DateTime?) p); | |
| 8453 if (p is DateTimeOffset?) return ToSqlString((DateTimeOffset?)p); | |
| 8454 if (p is Decimal?) return ToSqlString((Decimal?) p); | |
| 8455 if (p is Double?) return ToSqlString((Double?) p); | |
| 8456 if (p is Guid?) return ToSqlString((Guid?) p); | |
| 8457 if (p is Int16?) return ToSqlString((Int16?) p); | |
| 8458 if (p is Int32?) return ToSqlString((Int32?) p); | |
| 8459 if (p is Int64?) return ToSqlString((Int64?) p); | |
| 8460 if (p is SByte?) return ToSqlString((SByte?) p); | |
| 8461 if (p is Single?) return ToSqlString((Single?) p); | |
| 8462 if (p is TimeSpan?) return ToSqlString((TimeSpan?) p); | |
| 8463 if (p is UInt16?) return ToSqlString((UInt16?) p); | |
| 8464 if (p is UInt32?) return ToSqlString((UInt32?) p); | |
| 8465 if (p is UInt64?) return ToSqlString((UInt64?) p); | |
| 8466 } | |
| 8467 | |
| 8468 // Sql Types | |
| 8469 // | |
| 8470 if (p is INullable) | |
| 8471 { | |
| 8472 if (p is SqlBoolean) return ToSqlString((SqlBoolean) p); | |
| 8473 if (p is SqlByte) return ToSqlString((SqlByte) p); | |
| 8474 if (p is SqlChars) return ToSqlString((SqlChars) p); | |
| 8475 if (p is SqlDecimal) return ToSqlString((SqlDecimal) p); | |
| 8476 if (p is SqlDouble) return ToSqlString((SqlDouble) p); | |
| 8477 if (p is SqlGuid) return ToSqlString((SqlGuid) p); | |
| 8478 if (p is SqlInt16) return ToSqlString((SqlInt16) p); | |
| 8479 if (p is SqlInt32) return ToSqlString((SqlInt32) p); | |
| 8480 if (p is SqlInt64) return ToSqlString((SqlInt64) p); | |
| 8481 if (p is SqlMoney) return ToSqlString((SqlMoney) p); | |
| 8482 if (p is SqlSingle) return ToSqlString((SqlSingle) p); | |
| 8483 if (p is SqlXml) return ToSqlString((SqlXml) p); | |
| 8484 } | |
| 8485 | |
| 8486 // Other Types | |
| 8487 // | |
| 8488 if (p is Binary) return ToSqlString((Binary) p); | |
| 8489 if (p is Byte[]) return ToSqlString((Byte[]) p); | |
| 8490 if (p is Type) return ToSqlString((Type) p); | |
| 8491 if (p is XElement) return ToSqlString((XElement) p); | |
| 8492 if (p is XmlDocument) return ToSqlString((XmlDocument) p); | |
| 8493 | |
| 8494 throw CreateInvalidCastException(p.GetType(), typeof(SqlString)); | |
| 8495 } | |
| 8496 | |
| 8497 #endif | |
| 8498 | |
| 8499 #endregion | |
| 8500 | |
| 8501 #region SqlXml | |
| 8502 | |
| 8503 #if !SILVERLIGHT | |
| 8504 | |
| 8505 // Simple Types | |
| 8506 // | |
| 8507 /// <summary>Converts the value from <c>String</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8508 public static SqlXml ToSqlXml(String p) { return p == null ? SqlXml.Null : new SqlXml(new XmlTextReader(new StringReader(p))); } | |
| 8509 | |
| 8510 // Sql Types | |
| 8511 // | |
| 8512 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8513 public static SqlXml ToSqlXml(SqlBinary p) { return p.IsNull ? SqlXml.Null : new SqlXml(new MemoryStream(p.Value)); } | |
| 8514 /// <summary>Converts the value from <c>SqlBytes</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8515 public static SqlXml ToSqlXml(SqlBytes p) { return p.IsNull ? SqlXml.Null : new SqlXml(p.Stream); } | |
| 8516 /// <summary>Converts the value from <c>SqlChars</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8517 public static SqlXml ToSqlXml(SqlChars p) { return p.IsNull ? SqlXml.Null : new SqlXml(new XmlTextReader(new StringReader(p.ToSqlString().Value))); } | |
| 8518 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8519 public static SqlXml ToSqlXml(SqlString p) { return p.IsNull ? SqlXml.Null : new SqlXml(new XmlTextReader(new StringReader(p.Value))); } | |
| 8520 | |
| 8521 // Other Types | |
| 8522 // | |
| 8523 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8524 public static SqlXml ToSqlXml(Binary p) { return p == null ? SqlXml.Null : new SqlXml(new MemoryStream(p.ToArray())); } | |
| 8525 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8526 public static SqlXml ToSqlXml(Byte[] p) { return p == null ? SqlXml.Null : new SqlXml(new MemoryStream(p)); } | |
| 8527 /// <summary>Converts the value from <c>Char[]</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8528 public static SqlXml ToSqlXml(Char[] p) { return p == null ? SqlXml.Null : new SqlXml(new XmlTextReader(new StringReader(new string(p)))); } | |
| 8529 /// <summary>Converts the value from <c>Stream</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8530 public static SqlXml ToSqlXml(Stream p) { return p == null ? SqlXml.Null : new SqlXml(p); } | |
| 8531 /// <summary>Converts the value from <c>XElement</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8532 public static SqlXml ToSqlXml(XElement p) { return p == null ? SqlXml.Null : new SqlXml(new XmlTextReader(new StringReader(p.ToString()))); } | |
| 8533 /// <summary>Converts the value from <c>XmlDocument</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8534 public static SqlXml ToSqlXml(XmlDocument p) { return p == null ? SqlXml.Null : new SqlXml(new XmlTextReader(new StringReader(p.InnerXml))); } | |
| 8535 /// <summary>Converts the value from <c>XmlReader</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8536 public static SqlXml ToSqlXml(XmlReader p) { return p == null ? SqlXml.Null : new SqlXml(p); } | |
| 8537 | |
| 8538 // From Object | |
| 8539 // | |
| 8540 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>SqlXml</c> value.</summary> | |
| 8541 public static SqlXml ToSqlXml(object p) | |
| 8542 { | |
| 8543 if (p == null) return SqlXml.Null; | |
| 8544 | |
| 8545 if (p is SqlXml) return (SqlXml)p; | |
| 8546 | |
| 8547 var type = p.GetType(); | |
| 8548 | |
| 8549 // Primitive types | |
| 8550 // | |
| 8551 switch (Type.GetTypeCode(type)) | |
| 8552 { | |
| 8553 case TypeCode.DBNull : return SqlXml.Null; | |
| 8554 case TypeCode.String : return ToSqlXml((String)p); | |
| 8555 } | |
| 8556 | |
| 8557 // Sql Types | |
| 8558 // | |
| 8559 if (p is INullable) | |
| 8560 { | |
| 8561 if (p is SqlBinary) return ToSqlXml((SqlBinary) p); | |
| 8562 if (p is SqlBytes) return ToSqlXml((SqlBytes) p); | |
| 8563 if (p is SqlChars) return ToSqlXml((SqlChars) p); | |
| 8564 if (p is SqlString) return ToSqlXml((SqlString) p); | |
| 8565 } | |
| 8566 | |
| 8567 // Other Types | |
| 8568 // | |
| 8569 if (p is Binary) return ToSqlXml((Binary) p); | |
| 8570 if (p is Byte[]) return ToSqlXml((Byte[]) p); | |
| 8571 if (p is Char[]) return ToSqlXml((Char[]) p); | |
| 8572 if (p is Stream) return ToSqlXml((Stream) p); | |
| 8573 if (p is XElement) return ToSqlXml((XElement) p); | |
| 8574 if (p is XmlDocument) return ToSqlXml((XmlDocument)p); | |
| 8575 if (p is XmlReader) return ToSqlXml((XmlReader) p); | |
| 8576 | |
| 8577 throw CreateInvalidCastException(p.GetType(), typeof(SqlXml)); | |
| 8578 } | |
| 8579 | |
| 8580 #endif | |
| 8581 | |
| 8582 #endregion | |
| 8583 | |
| 8584 #endregion | |
| 8585 | |
| 8586 #region Other Types | |
| 8587 | |
| 8588 #region Binary | |
| 8589 | |
| 8590 #endregion | |
| 8591 | |
| 8592 #region Byte[] | |
| 8593 | |
| 8594 // Simple Types | |
| 8595 // | |
| 8596 /// <summary>Converts the value from <c>Boolean</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8597 public static Byte[] ToByteArray(Boolean p) { return BitConverter.GetBytes(p); } | |
| 8598 /// <summary>Converts the value from <c>Byte</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8599 public static Byte[] ToByteArray(Byte p) { return new[] { p }; } | |
| 8600 /// <summary>Converts the value from <c>Char</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8601 public static Byte[] ToByteArray(Char p) { return BitConverter.GetBytes(p); } | |
| 8602 #if !SILVERLIGHT | |
| 8603 /// <summary>Converts the value from <c>DateTime</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8604 public static Byte[] ToByteArray(DateTime p) { return ToByteArray(p.ToBinary()); } | |
| 8605 #endif | |
| 8606 #if !SILVERLIGHT | |
| 8607 /// <summary>Converts the value from <c>DateTimeOffset</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8608 public static Byte[] ToByteArray(DateTimeOffset p) { return ToByteArray(p.LocalDateTime.ToBinary()); } | |
| 8609 #endif | |
| 8610 /// <summary>Converts the value from <c>Double</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8611 public static Byte[] ToByteArray(Double p) { return BitConverter.GetBytes(p); } | |
| 8612 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8613 public static Byte[] ToByteArray(Guid p) { return p == Guid.Empty ? (Byte[])null : p.ToByteArray(); } | |
| 8614 /// <summary>Converts the value from <c>Int16</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8615 public static Byte[] ToByteArray(Int16 p) { return BitConverter.GetBytes(p); } | |
| 8616 /// <summary>Converts the value from <c>Int32</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8617 public static Byte[] ToByteArray(Int32 p) { return BitConverter.GetBytes(p); } | |
| 8618 /// <summary>Converts the value from <c>Int64</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8619 public static Byte[] ToByteArray(Int64 p) { return BitConverter.GetBytes(p); } | |
| 8620 /// <summary>Converts the value from <c>SByte</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8621 [CLSCompliant(false)] | |
| 8622 public static Byte[] ToByteArray(SByte p) { return new[] { checked((Byte)p) }; } | |
| 8623 /// <summary>Converts the value from <c>Single</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8624 public static Byte[] ToByteArray(Single p) { return BitConverter.GetBytes(p); } | |
| 8625 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8626 public static Byte[] ToByteArray(String p) { return p == null ? (Byte[])null : System.Text.Encoding.UTF8.GetBytes(p); } | |
| 8627 /// <summary>Converts the value from <c>TimeSpan</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8628 public static Byte[] ToByteArray(TimeSpan p) { return ToByteArray(p.Ticks); } | |
| 8629 /// <summary>Converts the value from <c>UInt16</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8630 [CLSCompliant(false)] | |
| 8631 public static Byte[] ToByteArray(UInt16 p) { return BitConverter.GetBytes(p); } | |
| 8632 /// <summary>Converts the value from <c>UInt32</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8633 [CLSCompliant(false)] | |
| 8634 public static Byte[] ToByteArray(UInt32 p) { return BitConverter.GetBytes(p); } | |
| 8635 /// <summary>Converts the value from <c>UInt64</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8636 [CLSCompliant(false)] | |
| 8637 public static Byte[] ToByteArray(UInt64 p) { return BitConverter.GetBytes(p); } | |
| 8638 | |
| 8639 // Nullable Types | |
| 8640 // | |
| 8641 /// <summary>Converts the value from <c>Boolean?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8642 public static Byte[] ToByteArray(Boolean? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8643 /// <summary>Converts the value from <c>Byte?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8644 public static Byte[] ToByteArray(Byte? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8645 /// <summary>Converts the value from <c>Char?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8646 public static Byte[] ToByteArray(Char? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8647 #if !SILVERLIGHT | |
| 8648 /// <summary>Converts the value from <c>DateTime?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8649 public static Byte[] ToByteArray(DateTime? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8650 #endif | |
| 8651 #if !SILVERLIGHT | |
| 8652 /// <summary>Converts the value from <c>DateTimeOffset?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8653 public static Byte[] ToByteArray(DateTimeOffset? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8654 #endif | |
| 8655 /// <summary>Converts the value from <c>Decimal?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8656 public static Byte[] ToByteArray(Decimal? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8657 /// <summary>Converts the value from <c>Double?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8658 public static Byte[] ToByteArray(Double? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8659 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8660 public static Byte[] ToByteArray(Guid? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8661 /// <summary>Converts the value from <c>Int16?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8662 public static Byte[] ToByteArray(Int16? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8663 /// <summary>Converts the value from <c>Int32?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8664 public static Byte[] ToByteArray(Int32? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8665 /// <summary>Converts the value from <c>Int64?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8666 public static Byte[] ToByteArray(Int64? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8667 /// <summary>Converts the value from <c>SByte?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8668 [CLSCompliant(false)] | |
| 8669 public static Byte[] ToByteArray(SByte? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8670 /// <summary>Converts the value from <c>Single?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8671 public static Byte[] ToByteArray(Single? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8672 /// <summary>Converts the value from <c>TimeSpan?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8673 public static Byte[] ToByteArray(TimeSpan? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8674 /// <summary>Converts the value from <c>UInt16?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8675 [CLSCompliant(false)] | |
| 8676 public static Byte[] ToByteArray(UInt16? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8677 /// <summary>Converts the value from <c>UInt32?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8678 [CLSCompliant(false)] | |
| 8679 public static Byte[] ToByteArray(UInt32? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8680 /// <summary>Converts the value from <c>UInt64?</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8681 [CLSCompliant(false)] | |
| 8682 public static Byte[] ToByteArray(UInt64? p) { return p.HasValue ? ToByteArray(p.Value) : (Byte[])null; } | |
| 8683 | |
| 8684 // Other Types | |
| 8685 // | |
| 8686 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8687 public static Byte[] ToByteArray(Binary p) { return p == null ? (Byte[])null : p.ToArray(); } | |
| 8688 | |
| 8689 #if !SILVERLIGHT | |
| 8690 | |
| 8691 // Sql Types | |
| 8692 // | |
| 8693 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8694 public static Byte[] ToByteArray(SqlBinary p) { return p.IsNull ? (Byte[])null : p.Value; } | |
| 8695 /// <summary>Converts the value from <c>SqlBoolean</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8696 public static Byte[] ToByteArray(SqlBoolean p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8697 /// <summary>Converts the value from <c>SqlByte</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8698 public static Byte[] ToByteArray(SqlByte p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8699 /// <summary>Converts the value from <c>SqlBytes</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8700 public static Byte[] ToByteArray(SqlBytes p) { return p.IsNull ? (Byte[])null : p.Value; } | |
| 8701 /// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8702 public static Byte[] ToByteArray(SqlDecimal p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8703 /// <summary>Converts the value from <c>SqlDouble</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8704 public static Byte[] ToByteArray(SqlDouble p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8705 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8706 public static Byte[] ToByteArray(SqlGuid p) { return p.IsNull ? (Byte[])null : p.ToByteArray(); } | |
| 8707 /// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8708 public static Byte[] ToByteArray(SqlInt16 p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8709 /// <summary>Converts the value from <c>SqlInt32</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8710 public static Byte[] ToByteArray(SqlInt32 p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8711 /// <summary>Converts the value from <c>SqlInt64</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8712 public static Byte[] ToByteArray(SqlInt64 p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8713 /// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8714 public static Byte[] ToByteArray(SqlMoney p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8715 /// <summary>Converts the value from <c>SqlSingle</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8716 public static Byte[] ToByteArray(SqlSingle p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8717 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8718 public static Byte[] ToByteArray(SqlString p) { return p.IsNull ? (Byte[])null : ToByteArray(p.Value); } | |
| 8719 | |
| 8720 #endif | |
| 8721 | |
| 8722 // From Object | |
| 8723 // | |
| 8724 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Byte[]</c> value.</summary> | |
| 8725 public static Byte[] ToByteArray(object p) | |
| 8726 { | |
| 8727 if (p == null) return null; | |
| 8728 | |
| 8729 if (p is Byte[]) return (Byte[])p; | |
| 8730 | |
| 8731 var type = p.GetType(); | |
| 8732 | |
| 8733 // Primitive types | |
| 8734 // | |
| 8735 switch (Type.GetTypeCode(type)) | |
| 8736 { | |
| 8737 case TypeCode.DBNull : return null; | |
| 8738 case TypeCode.Decimal : return ToByteArray((Decimal) p); | |
| 8739 case TypeCode.String : return ToByteArray((String) p); | |
| 8740 case TypeCode.Byte : return ToByteArray((Byte) p); | |
| 8741 case TypeCode.SByte : return ToByteArray((SByte) p); | |
| 8742 #if !SILVERLIGHT | |
| 8743 case TypeCode.DateTime : return ToByteArray((DateTime)p); | |
| 8744 #endif | |
| 8745 case TypeCode.Int16 : return ToByteArray((Int16) p); | |
| 8746 case TypeCode.Int32 : return ToByteArray((Int32) p); | |
| 8747 case TypeCode.Int64 : return ToByteArray((Int64) p); | |
| 8748 case TypeCode.UInt16 : return ToByteArray((UInt16) p); | |
| 8749 case TypeCode.UInt32 : return ToByteArray((UInt32) p); | |
| 8750 case TypeCode.UInt64 : return ToByteArray((UInt64) p); | |
| 8751 case TypeCode.Single : return ToByteArray((Single) p); | |
| 8752 case TypeCode.Double : return ToByteArray((Double) p); | |
| 8753 case TypeCode.Boolean : return ToByteArray((Boolean) p); | |
| 8754 case TypeCode.Char : return ToByteArray((Char) p); | |
| 8755 } | |
| 8756 | |
| 8757 // Simple Types | |
| 8758 // | |
| 8759 #if !SILVERLIGHT | |
| 8760 if (p is DateTimeOffset) return ToByteArray((DateTimeOffset) p); | |
| 8761 #endif | |
| 8762 if (p is Guid) return ToByteArray((Guid) p); | |
| 8763 if (p is TimeSpan) return ToByteArray((TimeSpan) p); | |
| 8764 | |
| 8765 // Nullable Types | |
| 8766 // | |
| 8767 if (type.IsGenericType) | |
| 8768 { | |
| 8769 if (p is Boolean?) return ToByteArray((Boolean?) p); | |
| 8770 if (p is Byte?) return ToByteArray((Byte?) p); | |
| 8771 if (p is Char?) return ToByteArray((Char?) p); | |
| 8772 #if !SILVERLIGHT | |
| 8773 if (p is DateTime?) return ToByteArray((DateTime?) p); | |
| 8774 #endif | |
| 8775 #if !SILVERLIGHT | |
| 8776 if (p is DateTimeOffset?) return ToByteArray((DateTimeOffset?)p); | |
| 8777 #endif | |
| 8778 if (p is Decimal?) return ToByteArray((Decimal?) p); | |
| 8779 if (p is Double?) return ToByteArray((Double?) p); | |
| 8780 if (p is Guid?) return ToByteArray((Guid?) p); | |
| 8781 if (p is Int16?) return ToByteArray((Int16?) p); | |
| 8782 if (p is Int32?) return ToByteArray((Int32?) p); | |
| 8783 if (p is Int64?) return ToByteArray((Int64?) p); | |
| 8784 if (p is SByte?) return ToByteArray((SByte?) p); | |
| 8785 if (p is Single?) return ToByteArray((Single?) p); | |
| 8786 if (p is TimeSpan?) return ToByteArray((TimeSpan?) p); | |
| 8787 if (p is UInt16?) return ToByteArray((UInt16?) p); | |
| 8788 if (p is UInt32?) return ToByteArray((UInt32?) p); | |
| 8789 if (p is UInt64?) return ToByteArray((UInt64?) p); | |
| 8790 } | |
| 8791 | |
| 8792 // Other Types | |
| 8793 // | |
| 8794 if (p is Binary) return ToByteArray((Binary) p); | |
| 8795 if (p is Char[]) return ToByteArray((Char[]) p); | |
| 8796 if (p is Stream) return ToByteArray((Stream) p); | |
| 8797 | |
| 8798 #if !SILVERLIGHT | |
| 8799 | |
| 8800 // Sql Types | |
| 8801 // | |
| 8802 if (p is INullable) | |
| 8803 { | |
| 8804 if (p is SqlBinary) return ToByteArray((SqlBinary) p); | |
| 8805 if (p is SqlBoolean) return ToByteArray((SqlBoolean) p); | |
| 8806 if (p is SqlByte) return ToByteArray((SqlByte) p); | |
| 8807 if (p is SqlBytes) return ToByteArray((SqlBytes) p); | |
| 8808 if (p is SqlDecimal) return ToByteArray((SqlDecimal) p); | |
| 8809 if (p is SqlDouble) return ToByteArray((SqlDouble) p); | |
| 8810 if (p is SqlGuid) return ToByteArray((SqlGuid) p); | |
| 8811 if (p is SqlInt16) return ToByteArray((SqlInt16) p); | |
| 8812 if (p is SqlInt32) return ToByteArray((SqlInt32) p); | |
| 8813 if (p is SqlInt64) return ToByteArray((SqlInt64) p); | |
| 8814 if (p is SqlMoney) return ToByteArray((SqlMoney) p); | |
| 8815 if (p is SqlSingle) return ToByteArray((SqlSingle) p); | |
| 8816 if (p is SqlString) return ToByteArray((SqlString) p); | |
| 8817 } | |
| 8818 | |
| 8819 #endif | |
| 8820 | |
| 8821 throw CreateInvalidCastException(p.GetType(), typeof(Byte[])); | |
| 8822 } | |
| 8823 | |
| 8824 #endregion | |
| 8825 | |
| 8826 #region Char[] | |
| 8827 | |
| 8828 #endregion | |
| 8829 | |
| 8830 #region Stream | |
| 8831 | |
| 8832 // Simple Types | |
| 8833 // | |
| 8834 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8835 public static Stream ToStream(Guid p) { return p == Guid.Empty ? Stream.Null : new MemoryStream(p.ToByteArray()); } | |
| 8836 | |
| 8837 // Nullable Types | |
| 8838 // | |
| 8839 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8840 public static Stream ToStream(Guid? p) { return p.HasValue ? new MemoryStream(p.Value.ToByteArray()) : Stream.Null; } | |
| 8841 | |
| 8842 // Other Types | |
| 8843 // | |
| 8844 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8845 public static Stream ToStream(Binary p) { return p == null ? Stream.Null : new MemoryStream(p.ToArray()); } | |
| 8846 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8847 public static Stream ToStream(Byte[] p) { return p == null ? Stream.Null : new MemoryStream(p); } | |
| 8848 | |
| 8849 #if !SILVERLIGHT | |
| 8850 | |
| 8851 // Sql Types | |
| 8852 // | |
| 8853 /// <summary>Converts the value from <c>SqlBinary</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8854 public static Stream ToStream(SqlBinary p) { return p.IsNull ? Stream.Null : new MemoryStream(p.Value); } | |
| 8855 /// <summary>Converts the value from <c>SqlBytes</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8856 public static Stream ToStream(SqlBytes p) { return p.IsNull ? Stream.Null : p.Stream; } | |
| 8857 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8858 public static Stream ToStream(SqlGuid p) { return p.IsNull ? Stream.Null : new MemoryStream(p.Value.ToByteArray()); } | |
| 8859 | |
| 8860 #endif | |
| 8861 | |
| 8862 // From Object | |
| 8863 // | |
| 8864 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Stream</c> value.</summary> | |
| 8865 public static Stream ToStream(object p) | |
| 8866 { | |
| 8867 if (p == null || p is DBNull) return Stream.Null; | |
| 8868 | |
| 8869 if (p is Stream) return (Stream)p; | |
| 8870 | |
| 8871 // Simple Types | |
| 8872 // | |
| 8873 if (p is Guid) return ToStream((Guid) p); | |
| 8874 | |
| 8875 // Nullable Types | |
| 8876 // | |
| 8877 var type = p.GetType(); | |
| 8878 | |
| 8879 if (type.IsGenericType) | |
| 8880 { | |
| 8881 if (p is Guid?) return ToStream((Guid?) p); | |
| 8882 } | |
| 8883 | |
| 8884 // Other Types | |
| 8885 // | |
| 8886 if (p is Binary) return ToStream((Binary) p); | |
| 8887 if (p is Byte[]) return ToStream((Byte[]) p); | |
| 8888 | |
| 8889 #if !SILVERLIGHT | |
| 8890 | |
| 8891 // Sql Types | |
| 8892 // | |
| 8893 if (p is INullable) | |
| 8894 { | |
| 8895 if (p is SqlBinary) return ToStream((SqlBinary)p); | |
| 8896 if (p is SqlBytes) return ToStream((SqlBytes) p); | |
| 8897 if (p is SqlGuid) return ToStream((SqlGuid) p); | |
| 8898 } | |
| 8899 | |
| 8900 #endif | |
| 8901 | |
| 8902 throw CreateInvalidCastException(p.GetType(), typeof(Stream)); | |
| 8903 } | |
| 8904 | |
| 8905 #endregion | |
| 8906 | |
| 8907 #region Type | |
| 8908 | |
| 8909 // Simple Types | |
| 8910 // | |
| 8911 #if !SILVERLIGHT | |
| 8912 /// <summary>Converts the value from <c>Guid</c> to an equivalent <c>Type</c> value.</summary> | |
| 8913 public static Type ToType(Guid p) { return p == Guid.Empty ? (Type)null : Type.GetTypeFromCLSID(p); } | |
| 8914 #endif | |
| 8915 /// <summary>Converts the value from <c>String</c> to an equivalent <c>Type</c> value.</summary> | |
| 8916 public static Type ToType(String p) { return p == null ? (Type)null : Type.GetType(p); } | |
| 8917 | |
| 8918 // Nullable Types | |
| 8919 // | |
| 8920 #if !SILVERLIGHT | |
| 8921 /// <summary>Converts the value from <c>Guid?</c> to an equivalent <c>Type</c> value.</summary> | |
| 8922 public static Type ToType(Guid? p) { return p.HasValue ? Type.GetTypeFromCLSID(p.Value) : (Type)null; } | |
| 8923 #endif | |
| 8924 | |
| 8925 // Other Types | |
| 8926 // | |
| 8927 #if !SILVERLIGHT | |
| 8928 /// <summary>Converts the value from <c>Binary</c> to an equivalent <c>Type</c> value.</summary> | |
| 8929 public static Type ToType(Binary p) { return p == null ? (Type)null : Type.GetTypeFromCLSID(ToGuid(p.ToArray())); } | |
| 8930 #endif | |
| 8931 #if !SILVERLIGHT | |
| 8932 /// <summary>Converts the value from <c>Byte[]</c> to an equivalent <c>Type</c> value.</summary> | |
| 8933 public static Type ToType(Byte[] p) { return p == null ? (Type)null : Type.GetTypeFromCLSID(ToGuid(p)); } | |
| 8934 #endif | |
| 8935 /// <summary>Converts the value from <c>Char[]</c> to an equivalent <c>Type</c> value.</summary> | |
| 8936 public static Type ToType(Char[] p) { return p == null ? (Type)null : Type.GetType(new string(p)); } | |
| 8937 | |
| 8938 #if !SILVERLIGHT | |
| 8939 | |
| 8940 // Sql Types | |
| 8941 // | |
| 8942 /// <summary>Converts the value from <c>SqlChars</c> to an equivalent <c>Type</c> value.</summary> | |
| 8943 public static Type ToType(SqlChars p) { return p.IsNull ? (Type)null : Type.GetType(new string(p.Value)); } | |
| 8944 /// <summary>Converts the value from <c>SqlGuid</c> to an equivalent <c>Type</c> value.</summary> | |
| 8945 public static Type ToType(SqlGuid p) { return p.IsNull ? (Type)null : Type.GetTypeFromCLSID(p.Value); } | |
| 8946 /// <summary>Converts the value from <c>SqlString</c> to an equivalent <c>Type</c> value.</summary> | |
| 8947 public static Type ToType(SqlString p) { return p.IsNull ? (Type)null : Type.GetType(p.Value); } | |
| 8948 | |
| 8949 #endif | |
| 8950 | |
| 8951 // From Object | |
| 8952 // | |
| 8953 /// <summary>Converts the value from <c>Object</c> to an equivalent <c>Type</c> value.</summary> | |
| 8954 public static Type ToType(object p) | |
| 8955 { | |
| 8956 if (p == null) return null; | |
| 8957 | |
| 8958 if (p is Type) return (Type)p; | |
| 8959 | |
| 8960 var type = p.GetType(); | |
| 8961 | |
| 8962 // Primitive types | |
| 8963 // | |
| 8964 switch (Type.GetTypeCode(type)) | |
| 8965 { | |
| 8966 case TypeCode.DBNull : return null; | |
| 8967 case TypeCode.String : return ToType((String)p); | |
| 8968 } | |
| 8969 | |
| 8970 // Simple Types | |
| 8971 // | |
| 8972 #if !SILVERLIGHT | |
| 8973 if (p is Guid) return ToType((Guid) p); | |
| 8974 #endif | |
| 8975 | |
| 8976 // Nullable Types | |
| 8977 // | |
| 8978 if (type.IsGenericType) | |
| 8979 { | |
| 8980 #if !SILVERLIGHT | |
| 8981 if (p is Guid?) return ToType((Guid?) p); | |
| 8982 #endif | |
| 8983 } | |
| 8984 | |
| 8985 // Other Types | |
| 8986 // | |
| 8987 #if !SILVERLIGHT | |
| 8988 if (p is Binary) return ToType((Binary) p); | |
| 8989 #endif | |
| 8990 #if !SILVERLIGHT | |
| 8991 if (p is Byte[]) return ToType((Byte[]) p); | |
| 8992 #endif | |
| 8993 if (p is Char[]) return ToType((Char[]) p); | |
| 8994 | |
| 8995 #if !SILVERLIGHT | |
| 8996 | |
| 8997 // Sql Types | |
| 8998 // | |
| 8999 if (p is INullable) | |
| 9000 { | |
| 9001 if (p is SqlChars) return ToType((SqlChars) p); | |
| 9002 if (p is SqlGuid) return ToType((SqlGuid) p); | |
| 9003 if (p is SqlString) return ToType((SqlString)p); | |
| 9004 } | |
| 9005 | |
| 9006 #endif | |
| 9007 | |
| 9008 throw CreateInvalidCastException(p.GetType(), typeof(Type)); | |
| 9009 } | |
| 9010 | |
| 9011 #endregion | |
| 9012 | |
| 9013 #region XmlDocument | |
| 9014 | |
| 9015 #if !SILVERLIGHT | |
| 9016 | |
| 9017 #endif | |
| 9018 | |
| 9019 #endregion | |
| 9020 | |
| 9021 #region XmlReader | |
| 9022 | |
| 9023 #if !SILVERLIGHT | |
| 9024 | |
| 9025 #endif | |
| 9026 | |
| 9027 #endregion | |
| 9028 | |
| 9029 #endregion | |
| 9030 } | |
| 9031 } |
