/// <summary> /// Reads the JSON representation of the object. /// </summary> public override object ReadJson( Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer ) { if( typeof( DataService.Attribute ) == objectType ) { var result = default( DataService.Attribute ); if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.PropertyName ) { var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture ); var value = reader.ReadAsString(); result = new DataService.Attribute( key, value ); } return result; } else { var result = new List<DataService.Attribute>(); if( reader.TokenType == Newtonsoft.Json.JsonToken.StartObject ) { while( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.PropertyName ) { var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture ); var value = reader.ReadAsString(); result.Add( new DataService.Attribute( key, value ) ); } } return result.ToArray(); } }
/// <summary> /// Reads the JSON representation of the object. /// </summary> public override object ReadJson( Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer ) { var catalog = new Catalog(); if( reader.TokenType == Newtonsoft.Json.JsonToken.StartObject ) { while( reader.Read() && reader.TokenType != Newtonsoft.Json.JsonToken.EndObject ) { switch( reader.Value.ToString() ) { case "name": catalog.Name = reader.ReadAsString(); break; case "uuid": catalog.Uuid = new Guid( reader.ReadAsString() ); break; case "validAttributes": if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.StartArray ) { var atts = new List<ushort>(); while( reader.Read() && reader.TokenType != Newtonsoft.Json.JsonToken.EndArray ) { atts.Add( Convert.ToUInt16( reader.Value ) ); } catalog.ValidAttributes = atts.ToArray(); } break; case "catalogEntries": if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.StartArray ) { if( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.StartObject ) { var entries = new List< CatalogEntry >(); while( reader.TokenType != Newtonsoft.Json.JsonToken.EndArray ) { entries.Add(serializer.Deserialize<CatalogEntry>( reader )); reader.Read(); } catalog.CatalogEntries = entries.ToArray(); } } break; } } } return catalog; }
/// <summary> /// Reads the JSON representation of the object. /// </summary> public override object ReadJson( Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer ) { var key = default( ushort ); var length = default( ushort ); var queryEfficient = default( bool ); var description = default( string ); var attributeDefinitionType = default( string ); var type = default( AttributeType ); var catalogUuid = default( Guid ); while( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.PropertyName ) { switch( reader.Value.ToString() ) { case "key": key = ushort.Parse( reader.ReadAsString(), CultureInfo.InvariantCulture ); break; case "queryEfficient": queryEfficient = bool.Parse( reader.ReadAsString() ); break; case "description": description = reader.ReadAsString(); break; case "length": length = ushort.Parse( reader.ReadAsString(), CultureInfo.InvariantCulture ); break; case "type": type = (AttributeType)Enum.Parse( typeof( AttributeType ), reader.ReadAsString() ); break; case "catalog": catalogUuid = Guid.Parse( reader.ReadAsString() ); break; case "definitionType": attributeDefinitionType = reader.ReadAsString(); break; } } if( attributeDefinitionType == "AttributeDefinition" ) return new AttributeDefinition { Description = description, Key = key, Length = length, QueryEfficient = queryEfficient, Type = type }; if( attributeDefinitionType == "CatalogAttributeDefinition" ) return new CatalogAttributeDefinition { Description = description, Key = key, QueryEfficient = queryEfficient, Catalog = catalogUuid }; return null; }
/// <summary> /// Reads the JSON representation of the object. /// </summary> public override object ReadJson( Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer ) { var catalogueEntry = new CatalogEntry(); while( reader.Read() && reader.TokenType == Newtonsoft.Json.JsonToken.PropertyName ) { switch( reader.Value.ToString() ) { case "key": catalogueEntry.Key = short.Parse( reader.ReadAsString(), CultureInfo.InvariantCulture ); break; case "attributes": reader.Read(); catalogueEntry.Attributes = serializer.Deserialize<DataService.Attribute[]>( reader ); break; } } return catalogueEntry; }