/// <summary> /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>. /// </summary> /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param> /// <returns> /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false. /// </returns> /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception> public override bool Equals(object obj) { JsonRaw raw = obj as JsonRaw; if (raw == null) { return(false); } return(string.Compare(_content, raw.Content, StringComparison.OrdinalIgnoreCase) == 0); }
private object CreateObject(JsonReader reader, Type objectType, object existingValue, JsonConverter memberConverter) { _level++; object value; JsonConverter converter; if (memberConverter != null) { return(memberConverter.ReadJson(reader, objectType)); } else if (objectType != null && HasClassConverter(objectType, out converter)) { return(converter.ReadJson(reader, objectType)); } else if (objectType != null && HasMatchingConverter(objectType, out converter)) { return(converter.ReadJson(reader, objectType)); } else if (objectType == typeof(JsonRaw)) { return(JsonRaw.Create(reader)); } else { switch (reader.TokenType) { // populate a typed object or generic dictionary/array // depending upon whether an objectType was supplied case JsonToken.StartObject: if (objectType == null) { value = CreateJToken(reader); } else if (CollectionUtils.IsDictionaryType(objectType)) { if (existingValue == null) { value = CreateAndPopulateDictionary(reader, objectType); } else { value = PopulateDictionary(CollectionUtils.CreateDictionaryWrapper(existingValue), reader); } } else { if (existingValue == null) { value = CreateAndPopulateObject(reader, objectType); } else { value = PopulateObject(existingValue, reader, objectType); } } break; case JsonToken.StartArray: if (objectType != null) { if (existingValue == null) { value = CreateAndPopulateList(reader, objectType); } else { value = PopulateList(CollectionUtils.CreateCollectionWrapper(existingValue), ReflectionUtils.GetCollectionItemType(objectType), reader); } } else { value = CreateJToken(reader); } break; case JsonToken.Integer: case JsonToken.Float: case JsonToken.String: case JsonToken.Boolean: case JsonToken.Date: value = EnsureType(reader.Value, objectType); break; case JsonToken.StartConstructor: case JsonToken.EndConstructor: string constructorName = reader.Value.ToString(); value = constructorName; break; case JsonToken.Null: case JsonToken.Undefined: if (objectType == typeof(DBNull)) { value = DBNull.Value; } else { value = null; } break; default: throw new JsonSerializationException("Unexpected token while deserializing object: " + reader.TokenType); } } _level--; return(value); }