Example #1
0
        private IXmlTemplateNode MoveToProperty(XmlReader reader, IEnumerator <IPropertyMap> properties, IXmlTemplateNode templateNode, XRoadMessage message, bool validateRequired)
        {
            IPropertyMap propertyMap = null;

            while (properties.MoveNext())
            {
                propertyMap = properties.Current;
                var propertyName = propertyMap.Definition.GetSerializedName();
                var propertyNode = templateNode[properties.Current.Definition.TemplateName, message.Version];

                if (reader.LocalName == propertyName)
                {
                    return(propertyNode);
                }

                if (!propertyMap.Definition.IsOptional)
                {
                    throw XRoadException.UnexpectedElementInQuery(Definition.Name, propertyName, reader.LocalName);
                }

                if (validateRequired && propertyNode != null && propertyNode.IsRequired)
                {
                    throw XRoadException.MissingRequiredPropertyValues(Enumerable.Repeat(propertyName, 1));
                }
            }

            if (propertyMap == null)
            {
                throw XRoadException.InvalidQuery($"Element `{reader.LocalName}` was unexpected at given location while deserializing type `{Definition.Name}`.");
            }
            else
            {
                throw XRoadException.UnexpectedElementInQuery(Definition.Name, propertyMap.Definition.GetSerializedName(), reader.LocalName);
            }
        }