Aarni Koskela avatar Aarni Koskela committed d39cbd2

More casts and such

Comments (0)

Files changed (1)

JsonParser/JsonParser.cs

 		}
 
 		public bool BoolValue {
-			get { return (_type == JsonValueType.Boolean ? _boolValue : false); }
+			get {
+				if (_type == JsonValueType.String) return !string.IsNullOrWhiteSpace(_strValue);
+				if (_type == JsonValueType.Boolean) return _boolValue;
+				if (_type == JsonValueType.Integer) return (_intValue != 0);
+				if (_type == JsonValueType.Double) return (_doubleValue != 0);
+				if (_type == JsonValueType.List) return (_listValue.Count > 0);
+				return false;
+			}
 		}
 
 		public int IntValue {
-			get { return (_type == JsonValueType.Integer ? _intValue : 0); }
+			get {
+				if (_type == JsonValueType.Boolean) return (_boolValue ? 1 : 0);
+				if (_type == JsonValueType.Integer) return _intValue;
+				if (_type == JsonValueType.Double) return (int)_doubleValue;
+				return 0;
+			}
 		}
 
 		public double DoubleValue {
-			get { return (_type == JsonValueType.Double ? _doubleValue : 0.0); }
+			get {
+				if (_type == JsonValueType.Boolean) return (_boolValue ? 1.0 : 0.0);
+				if (_type == JsonValueType.Integer) return (double)_intValue;
+				if (_type == JsonValueType.Double) return _doubleValue;
+				return 0.0;
+			}
+		}
+
+		public int Count {
+			get {
+				if (_type == JsonValueType.Boolean && _boolValue == false) return 0;
+				if (_type == JsonValueType.Null) return 0;
+				if (_type == JsonValueType.String) return _strValue.Length;
+				if (_type == JsonValueType.List) return _listValue.Count;
+				if (_type == JsonValueType.Dict) return _dictValue.Count;
+				return 1;
+			}
 		}
 
 		#endregion
 		}
 
 		
-		public static explicit operator int(JsonValue val) {
+		public static implicit operator int(JsonValue val) {
 			return val.IntValue; 
 		}
-		public static explicit operator double(JsonValue val) {
+		public static implicit operator double(JsonValue val) {
 			return val.DoubleValue;
 		}
-		public static explicit operator string(JsonValue val) {
+		public static implicit operator string(JsonValue val) {
 			return val.StrValue;
 		}
+		public static implicit operator bool(JsonValue val) {
+			return val.BoolValue;
+		}
+
 
 		#endregion
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.