private void Deserialise(XmlReader reader) { if (reader.Read() && reader.NodeType == XmlNodeType.Element) { if (string.Compare(StringUtils.ToPlural(_ObjectDefinition.SerialisationName), reader.Name, true) == 0) { reader.Read(); if (reader.Name.Equals("Links")) { Links = new List <Link>(); Links.Deserialise(reader); reader.Read(); } if (reader.Name.Equals("PageInfo")) { PageInfo = new PageInfo(); PageInfo.Deserialise(reader); reader.Read(); } Items = new List <ObjectInstance>(); if (reader.Name.Equals("Items")) { while (!reader.EOF) { Items.Add(new ObjectInstance(_ObjectDefinition, reader)); } } } } }
private void Deserialise(JsonReader reader) { if (reader.Read() && reader.State == TJsonReaderState.Object) { reader.Read(); if (reader.Text.Equals("Links")) { Links = new List <Link>(); Links.Deserialise(reader); reader.Read(); } if (reader.Text.Equals("PageInfo")) { PageInfo = new PageInfo(); PageInfo.Deserialise(reader); reader.Read(); } Items = new List <ObjectInstance>(); if (reader.Text.Equals("Items")) { while (reader.State != TJsonReaderState.EOF) { Items.Add(new ObjectInstance(_ObjectDefinition, reader)); } } } }
private void Deserialise(XmlReader reader) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (_Resource == null) { if (string.Compare(ObjectDefinition.SerialisationName, reader.Name, true) == 0) { _Resource = new Model.Object(); _Resource.ObjectDefinitionID = ObjectDefinition.ObjectDefinitionID; _Resource.ObjectID = ObjectDefinition.ObjectID; } } else { if (reader.Name.Equals("Links")) { Links = new List <Link>(); Links.Deserialise(reader); } else { Model.PropertyDefinition propertyDefinition = ObjectDefinition.GetPropertyBySerialisationName(reader.Name); if (propertyDefinition == null) { if (string.Compare(reader.Name, "InstanceID", true) == 0) { reader.Read(); _Resource.InstanceID = reader.Value; } } else { Model.Property property = new Model.Property(); property.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID; property.PropertyID = propertyDefinition.PropertyID; if (propertyDefinition.IsCollection) { XmlReader collectionReader = reader.ReadSubtree(); DeserialiseItems(propertyDefinition, property, collectionReader); } else { property.Value = new Model.PropertyValue(); property.Value.Value = GetValue(propertyDefinition.DataType, reader.ReadInnerXml()); } _Resource.Properties.Add(property); } } } } else if (reader.NodeType == XmlNodeType.EndElement && string.Compare(ObjectDefinition.SerialisationName, reader.Name, true) == 0) { break; } } }
private void Deserialise(JsonReader reader) { Model.PropertyDefinition propertyDefinition = null; Model.Property property = null; bool isID = false; while (reader.Read()) { switch (reader.State) { case TJsonReaderState.NotSet: break; case TJsonReaderState.Array: break; case TJsonReaderState.BOF: break; case TJsonReaderState.Boolean: if (propertyDefinition != null) { Model.PropertyValue propertyValue = new Model.PropertyValue(reader.AsBoolean.ToString()); if (propertyDefinition.IsCollection) { if (property.Values == null) { property.Values = new List <Model.PropertyValue>(); } property.Values.Add(propertyValue); } else { property.Value = new Model.PropertyValue(propertyValue.Value); } } break; case TJsonReaderState.EndArray: propertyDefinition = null; break; case TJsonReaderState.EndObject: break; case TJsonReaderState.EOF: break; case TJsonReaderState.Member: if (reader.Text.Equals("Links")) { Links = new List <Link>(); Links.Deserialise(reader); } else { propertyDefinition = ObjectDefinition.GetPropertyBySerialisationName(reader.Text); if (propertyDefinition == null) { isID = string.Compare(reader.Text, "InstanceID", true) == 0; } else { isID = false; property = new Model.Property(); property.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID; property.PropertyID = propertyDefinition.PropertyID; if (_Resource != null) { _Resource.Properties.Add(property); } } } break; case TJsonReaderState.Null: break; case TJsonReaderState.Number: if (propertyDefinition != null) { Model.PropertyValue propertyValue = new Model.PropertyValue(reader.Text); if (propertyDefinition.IsCollection) { if (property.Values == null) { property.Values = new List <Model.PropertyValue>(); } property.Values.Add(propertyValue); } else { property.Value = new Model.PropertyValue(propertyValue.Value); } } break; case TJsonReaderState.Object: if (_Resource == null) { _Resource = new Model.Object(); _Resource.ObjectDefinitionID = ObjectDefinition.ObjectDefinitionID; _Resource.ObjectID = ObjectDefinition.ObjectID; } break; case TJsonReaderState.String: if (propertyDefinition == null) { if (isID) { _Resource.InstanceID = reader.Text; } } else { string text; if (propertyDefinition.DataType == Model.TPropertyDataType.DateTime) { text = GetDateTimeString(reader.Text); } else { text = reader.Text; } Model.PropertyValue propertyValue = new Model.PropertyValue(text); if (propertyDefinition.IsCollection) { if (property.Values == null) { property.Values = new List <Model.PropertyValue>(); } property.Values.Add(propertyValue); } else { property.Value = new Model.PropertyValue(propertyValue.Value); } } break; default: break; } } }
private void Deserialise(XmlReader reader) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (_Resource == null) { if (string.Compare(ObjectDefinition.SerialisationName, reader.Name, true) == 0) { _Resource = new Model.Object(); _Resource.ObjectDefinitionID = ObjectDefinition.ObjectDefinitionID; _Resource.ObjectID = ObjectDefinition.ObjectID; } } else { if (reader.Name.Equals("Links")) { Links = new List<Link>(); Links.Deserialise(reader); } else { Model.PropertyDefinition propertyDefinition = ObjectDefinition.GetPropertyBySerialisationName(reader.Name); if (propertyDefinition == null) { if (string.Compare(reader.Name, "InstanceID", true) == 0) { reader.Read(); _Resource.InstanceID = reader.Value; } } else { Model.Property property = new Model.Property(); property.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID; property.PropertyID = propertyDefinition.PropertyID; if (propertyDefinition.IsCollection) { XmlReader collectionReader = reader.ReadSubtree(); DeserialiseItems(propertyDefinition, property, collectionReader); } else { property.Value = new Model.PropertyValue(); property.Value.Value = GetValue(propertyDefinition.DataType, reader.ReadInnerXml()); } _Resource.Properties.Add(property); } } } } else if (reader.NodeType == XmlNodeType.EndElement && string.Compare(ObjectDefinition.SerialisationName, reader.Name, true) == 0) { break; } } }
private void Deserialise(JsonReader reader) { Model.PropertyDefinition propertyDefinition = null; Model.Property property = null; bool isID = false; while (reader.Read()) { switch (reader.State) { case TJsonReaderState.NotSet: break; case TJsonReaderState.Array: break; case TJsonReaderState.BOF: break; case TJsonReaderState.Boolean: if (propertyDefinition != null) { Model.PropertyValue propertyValue = new Model.PropertyValue(reader.AsBoolean.ToString()); if (propertyDefinition.IsCollection) { if (property.Values == null) property.Values = new List<Model.PropertyValue>(); property.Values.Add(propertyValue); } else { property.Value = new Model.PropertyValue(propertyValue.Value); } } break; case TJsonReaderState.EndArray: propertyDefinition = null; break; case TJsonReaderState.EndObject: break; case TJsonReaderState.EOF: break; case TJsonReaderState.Member: if (reader.Text.Equals("Links")) { Links = new List<Link>(); Links.Deserialise(reader); } else { propertyDefinition = ObjectDefinition.GetPropertyBySerialisationName(reader.Text); if (propertyDefinition == null) { isID = string.Compare(reader.Text, "InstanceID", true) == 0; } else { isID = false; property = new Model.Property(); property.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID; property.PropertyID = propertyDefinition.PropertyID; if (_Resource != null) _Resource.Properties.Add(property); } } break; case TJsonReaderState.Null: break; case TJsonReaderState.Number: if (propertyDefinition != null) { Model.PropertyValue propertyValue = new Model.PropertyValue(reader.Text); if (propertyDefinition.IsCollection) { if (property.Values == null) property.Values = new List<Model.PropertyValue>(); property.Values.Add(propertyValue); } else { property.Value = new Model.PropertyValue(propertyValue.Value); } } break; case TJsonReaderState.Object: if (_Resource == null) { _Resource = new Model.Object(); _Resource.ObjectDefinitionID = ObjectDefinition.ObjectDefinitionID; _Resource.ObjectID = ObjectDefinition.ObjectID; } break; case TJsonReaderState.String: if (propertyDefinition == null) { if (isID) _Resource.InstanceID = reader.Text; } else { string text; if (propertyDefinition.DataType == Model.TPropertyDataType.DateTime) { text = GetDateTimeString(reader.Text); } else { text = reader.Text; } Model.PropertyValue propertyValue = new Model.PropertyValue(text); if (propertyDefinition.IsCollection) { if (property.Values == null) property.Values = new List<Model.PropertyValue>(); property.Values.Add(propertyValue); } else { property.Value = new Model.PropertyValue(propertyValue.Value); } } break; default: break; } } }