@@ -1035,6 +1035,7 @@ public void Convert(ref BL src, ref SB dst)
10351035 /// </summary>
10361036 public bool TryParse ( ref TX src , out U1 dst )
10371037 {
1038+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
10381039 ulong res ;
10391040 if ( ! TryParse ( ref src , out res ) || res > U1 . MaxValue )
10401041 {
@@ -1050,6 +1051,7 @@ public bool TryParse(ref TX src, out U1 dst)
10501051 /// </summary>
10511052 public bool TryParse ( ref TX src , out U2 dst )
10521053 {
1054+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
10531055 ulong res ;
10541056 if ( ! TryParse ( ref src , out res ) || res > U2 . MaxValue )
10551057 {
@@ -1065,6 +1067,7 @@ public bool TryParse(ref TX src, out U2 dst)
10651067 /// </summary>
10661068 public bool TryParse ( ref TX src , out U4 dst )
10671069 {
1070+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
10681071 ulong res ;
10691072 if ( ! TryParse ( ref src , out res ) || res > U4 . MaxValue )
10701073 {
@@ -1080,12 +1083,7 @@ public bool TryParse(ref TX src, out U4 dst)
10801083 /// </summary>
10811084 public bool TryParse ( ref TX src , out U8 dst )
10821085 {
1083- if ( src . IsNA )
1084- {
1085- dst = 0 ;
1086- return false ;
1087- }
1088-
1086+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
10891087 int ichMin ;
10901088 int ichLim ;
10911089 string text = src . GetRawUnderlyingBufferInfo ( out ichMin , out ichLim ) ;
@@ -1203,6 +1201,8 @@ private bool IsStdMissing(ref TX src)
12031201 /// </summary>
12041202 public bool TryParseKey ( ref TX src , U8 min , U8 max , out U8 dst )
12051203 {
1204+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
1205+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing text value cannot be converted to unsigned integer type." ) ;
12061206 Contracts . Assert ( min <= max ) ;
12071207
12081208 // This simply ensures we don't have min == 0 and max == U8.MaxValue. This is illegal since
@@ -1227,7 +1227,7 @@ public bool TryParseKey(ref TX src, U8 min, U8 max, out U8 dst)
12271227 {
12281228 dst = 0 ;
12291229 // Return true only for standard forms for NA.
1230- return IsStdMissing ( ref src ) ;
1230+ return false ;
12311231 }
12321232
12331233 if ( min > uu || uu > max )
@@ -1277,13 +1277,9 @@ private bool TryParseCore(string text, int ich, int lim, out ulong dst)
12771277 /// </summary>
12781278 public bool TryParse ( ref TX src , out I1 dst )
12791279 {
1280- dst = default ;
1281- if ( src . IsNA )
1282- {
1283- dst = I1 . MinValue ;
1284- return true ;
1285- }
1280+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
12861281
1282+ dst = default ;
12871283 TryParseSigned ( I1 . MaxValue , ref src , out long ? res ) ;
12881284 Contracts . Check ( res . HasValue , "Value could not be parsed from text to sbyte." ) ;
12891285 Contracts . Check ( ( I1 ) res == res , "Overflow or underflow occured while converting value in text to sbyte." ) ;
@@ -1297,13 +1293,9 @@ public bool TryParse(ref TX src, out I1 dst)
12971293 /// </summary>
12981294 public bool TryParse ( ref TX src , out I2 dst )
12991295 {
1300- dst = default ;
1301- if ( src . IsNA )
1302- {
1303- dst = I2 . MinValue ;
1304- return true ;
1305- }
1296+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
13061297
1298+ dst = default ;
13071299 TryParseSigned ( I2 . MaxValue , ref src , out long ? res ) ;
13081300 Contracts . Check ( res . HasValue , "Value could not be parsed from text to short." ) ;
13091301 Contracts . Check ( ( I2 ) res == res , "Overflow or underflow occured while converting value in text to short." ) ;
@@ -1317,13 +1309,9 @@ public bool TryParse(ref TX src, out I2 dst)
13171309 /// </summary>
13181310 public bool TryParse ( ref TX src , out I4 dst )
13191311 {
1320- dst = default ;
1321- if ( src . IsNA )
1322- {
1323- dst = I4 . MinValue ;
1324- return true ;
1325- }
1312+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
13261313
1314+ dst = default ;
13271315 TryParseSigned ( I4 . MaxValue , ref src , out long ? res ) ;
13281316 Contracts . Check ( res . HasValue , "Value could not be parsed from text to int32." ) ;
13291317 Contracts . Check ( ( I4 ) res == res , "Overflow or underflow occured while converting value in text to int." ) ;
@@ -1337,13 +1325,9 @@ public bool TryParse(ref TX src, out I4 dst)
13371325 /// </summary>
13381326 public bool TryParse ( ref TX src , out I8 dst )
13391327 {
1340- dst = default ;
1341- if ( src . IsNA )
1342- {
1343- dst = I8 . MinValue ;
1344- return true ;
1345- }
1328+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
13461329
1330+ dst = default ;
13471331 TryParseSigned ( I8 . MaxValue , ref src , out long ? res ) ;
13481332 Contracts . Check ( res . HasValue , "Value could not be parsed from text to long." ) ;
13491333 dst = ( I8 ) res ;
@@ -1525,9 +1509,7 @@ public bool TryParse(ref TX src, out DZ dst)
15251509 // These throw an exception for unparsable and overflow values.
15261510 private I1 ParseI1 ( ref TX src )
15271511 {
1528- if ( src . IsNA )
1529- return I1 . MinValue ;
1530-
1512+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
15311513 TryParseSigned ( I1 . MaxValue , ref src , out long ? res ) ;
15321514 Contracts . Check ( res . HasValue , "Value could not be parsed from text to sbyte." ) ;
15331515 Contracts . Check ( ( I1 ) res == res , "Overflow or underflow occured while converting value in text to sbyte." ) ;
@@ -1536,9 +1518,7 @@ private I1 ParseI1(ref TX src)
15361518
15371519 private I2 ParseI2 ( ref TX src )
15381520 {
1539- if ( src . IsNA )
1540- return I2 . MinValue ;
1541-
1521+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
15421522 TryParseSigned ( I2 . MaxValue , ref src , out long ? res ) ;
15431523 Contracts . Check ( res . HasValue , "Value could not be parsed from text to short." ) ;
15441524 Contracts . Check ( ( I2 ) res == res , "Overflow or underflow occured while converting value in text to short." ) ;
@@ -1547,9 +1527,7 @@ private I2 ParseI2(ref TX src)
15471527
15481528 private I4 ParseI4 ( ref TX src )
15491529 {
1550- if ( src . IsNA )
1551- return I4 . MinValue ;
1552-
1530+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
15531531 TryParseSigned ( I4 . MaxValue , ref src , out long ? res ) ;
15541532 Contracts . Check ( res . HasValue , "Value could not be parsed from text to int." ) ;
15551533 Contracts . Check ( ( I4 ) res == res , "Overflow or underflow occured while converting value in text to int." ) ;
@@ -1558,9 +1536,7 @@ private I4 ParseI4(ref TX src)
15581536
15591537 private I8 ParseI8 ( ref TX src )
15601538 {
1561- if ( src . IsNA )
1562- return I8 . MinValue ;
1563-
1539+ Contracts . Check ( ! src . IsNA , "Missing text value cannot be converted to integer type." ) ;
15641540 TryParseSigned ( I8 . MaxValue , ref src , out long ? res ) ;
15651541 Contracts . Check ( res . HasValue , "Value could not be parsed from text to long." ) ;
15661542 return res . Value ;
@@ -1571,6 +1547,7 @@ private I8 ParseI8(ref TX src)
15711547 // unsigned integer types.
15721548 private U1 ParseU1 ( ref TX span )
15731549 {
1550+ Contracts . Check ( ! span . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
15741551 ulong res ;
15751552 if ( ! TryParse ( ref span , out res ) )
15761553 return 0 ;
@@ -1581,6 +1558,7 @@ private U1 ParseU1(ref TX span)
15811558
15821559 private U2 ParseU2 ( ref TX span )
15831560 {
1561+ Contracts . Check ( ! span . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
15841562 ulong res ;
15851563 if ( ! TryParse ( ref span , out res ) )
15861564 return 0 ;
@@ -1591,6 +1569,7 @@ private U2 ParseU2(ref TX span)
15911569
15921570 private U4 ParseU4 ( ref TX span )
15931571 {
1572+ Contracts . Check ( ! span . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
15941573 ulong res ;
15951574 if ( ! TryParse ( ref span , out res ) )
15961575 return 0 ;
@@ -1601,6 +1580,7 @@ private U4 ParseU4(ref TX span)
16011580
16021581 private U8 ParseU8 ( ref TX span )
16031582 {
1583+ Contracts . Check ( ! span . IsNA , "Missing text value cannot be converted to unsigned integer type." ) ;
16041584 ulong res ;
16051585 if ( ! TryParse ( ref span , out res ) )
16061586 return 0 ;
0 commit comments