private static bool ReadPropertyValue(XmlReader reader, IPropertyMap propertyMap, IXmlTemplateNode templateNode, XRoadMessage message, bool validateRequired, T dtoObject) { var templateName = propertyMap.Definition.TemplateName; var propertyNode = templateNode[templateName, message.Version]; if (propertyNode == null) { reader.ConsumeUnusedElement(); return(false); } var isNull = reader.IsNilElement(); if (validateRequired && isNull && propertyNode.IsRequired) { throw XRoadException.MissingRequiredPropertyValues(Enumerable.Repeat(propertyMap.Definition.Content.Name.LocalName, 1)); } if ((isNull || propertyMap.Deserialize(reader, dtoObject, propertyNode, message)) && !string.IsNullOrWhiteSpace(templateName)) { dtoObject.OnMemberDeserialized(templateName); } reader.ConsumeNilElement(isNull); return(propertyNode.IsRequired); }
public bool Deserialize(XmlReader reader, IXRoadSerializable dtoObject, IXmlTemplateNode templateNode, XRoadMessage message) { if (message.EnableFiltering && !filters.Contains(message.FilterName)) { reader.ConsumeUnusedElement(); return(false); } XName typeAttribute; if (typeMap.Definition.IsAnonymous && !(typeMap is IArrayTypeMap) && (typeAttribute = reader.GetTypeAttributeValue()) != null) { throw new UnknownTypeException($"Expected anonymous type, but `{typeAttribute}` was given.", Definition, typeMap.Definition, typeAttribute); } var concreteTypeMap = (typeMap.Definition.IsInheritable ? serializer.GetTypeMapFromXsiType(reader, Definition) : null) ?? typeMap; var propertyValue = concreteTypeMap.Deserialize(reader, templateNode, Definition.Content, message); if (propertyValue == null) { return(true); } setValueMethod(dtoObject, propertyValue); return(true); }
public bool Deserialize(XmlReader reader, IXRoadSerializable dtoObject, IXmlTemplateNode templateNode, XRoadMessage message) { if (message.EnableFiltering && !filters.Contains(message.FilterName)) { reader.ConsumeUnusedElement(); return(false); } string typeAttribute; if (typeMap.Definition.IsAnonymous && !(typeMap is IArrayTypeMap) && (typeAttribute = reader.GetAttribute("type", NamespaceConstants.XSI)) != null) { throw XRoadException.InvalidQuery($"Expected anonymous type, but `{typeAttribute}` was given."); } var concreteTypeMap = (typeMap.Definition.IsInheritable ? serializerCache.GetTypeMapFromXsiType(reader) : null) ?? typeMap; var propertyValue = concreteTypeMap.Deserialize(reader, templateNode, Definition, message); if (propertyValue == null) { return(true); } setValueMethod(dtoObject, propertyValue); return(true); }
private void ReadPropertyValue(XmlReader reader, IPropertyMap propertyMap, IXmlTemplateNode propertyNode, XRoadMessage message, bool validateRequired, T dtoObject) { if (propertyNode == null) { reader.ConsumeUnusedElement(); return; } var isNull = reader.IsNilElement(); if (validateRequired && isNull && propertyNode.IsRequired) { throw new ParameterRequiredException(Definition, propertyMap.Definition); } var templateName = propertyMap.Definition.TemplateName; if ((isNull || propertyMap.Deserialize(reader, dtoObject, propertyNode, message)) && !string.IsNullOrWhiteSpace(templateName)) { dtoObject.OnMemberDeserialized(templateName); } reader.ConsumeNilElement(isNull); }