@@ -73,6 +73,16 @@ public bool IsString {
7373 public ICollection < string > Keys {
7474 get { EnsureDictionary ( ) ; return inst_object . Keys ; }
7575 }
76+
77+ /// <summary>
78+ /// Determines whether the json contains an element that has the specified key.
79+ /// </summary>
80+ /// <param name="key">The key to locate in the json.</param>
81+ /// <returns>true if the json contains an element that has the specified key; otherwise, false.</returns>
82+ public Boolean ContainsKey ( String key ) {
83+ EnsureDictionary ( ) ;
84+ return this . inst_object . Keys . Contains ( key ) ;
85+ }
7686 #endregion
7787
7888
@@ -425,22 +435,27 @@ public static explicit operator Double (JsonData data)
425435 return data . inst_double ;
426436 }
427437
428- public static explicit operator Int32 ( JsonData data )
438+ public static explicit operator Int32 ( JsonData data )
429439 {
430- if ( data . type != JsonType . Int )
431- throw new InvalidCastException (
440+ if ( data . type != JsonType . Int && data . type != JsonType . Long )
441+ {
442+ throw new InvalidCastException (
432443 "Instance of JsonData doesn't hold an int" ) ;
444+ }
433445
434- return data . inst_int ;
446+ // cast may truncate data... but that's up to the user to consider
447+ return data . type == JsonType . Int ? data . inst_int : ( int ) data . inst_long ;
435448 }
436449
437- public static explicit operator Int64 ( JsonData data )
450+ public static explicit operator Int64 ( JsonData data )
438451 {
439452 if ( data . type != JsonType . Long && data . type != JsonType . Int )
440- throw new InvalidCastException (
441- "Instance of JsonData doesn't hold an int" ) ;
453+ {
454+ throw new InvalidCastException (
455+ "Instance of JsonData doesn't hold a long" ) ;
456+ }
442457
443- return ( data . type == JsonType . Long ) ? data . inst_long : data . inst_int ;
458+ return data . type == JsonType . Long ? data . inst_long : data . inst_int ;
444459 }
445460
446461 public static explicit operator String ( JsonData data )
@@ -823,7 +838,14 @@ public bool Equals (JsonData x)
823838 return false ;
824839
825840 if ( x . type != this . type )
826- return false ;
841+ {
842+ // further check to see if this is a long to int comparison
843+ if ( ( x . type != JsonType . Int && x . type != JsonType . Long )
844+ || ( this . type != JsonType . Int && this . type != JsonType . Long ) )
845+ {
846+ return false ;
847+ }
848+ }
827849
828850 switch ( this . type ) {
829851 case JsonType . None :
@@ -839,10 +861,26 @@ public bool Equals (JsonData x)
839861 return this . inst_string . Equals ( x . inst_string ) ;
840862
841863 case JsonType . Int :
842- return this . inst_int . Equals ( x . inst_int ) ;
864+ {
865+ if ( x . IsLong )
866+ {
867+ if ( x . inst_long < Int32 . MinValue || x . inst_long > Int32 . MaxValue )
868+ return false ;
869+ return this . inst_int . Equals ( ( int ) x . inst_long ) ;
870+ }
871+ return this . inst_int . Equals ( x . inst_int ) ;
872+ }
843873
844874 case JsonType . Long :
845- return this . inst_long . Equals ( x . inst_long ) ;
875+ {
876+ if ( x . IsInt )
877+ {
878+ if ( this . inst_long < Int32 . MinValue || this . inst_long > Int32 . MaxValue )
879+ return false ;
880+ return x . inst_int . Equals ( ( int ) this . inst_long ) ;
881+ }
882+ return this . inst_long . Equals ( x . inst_long ) ;
883+ }
846884
847885 case JsonType . Double :
848886 return this . inst_double . Equals ( x . inst_double ) ;
0 commit comments