Ejemplo n.º 1
0
        protected override void InitializeElementProperties(System.Xml.XmlReader reader, ref object obj, ITypeSerializationInfo info, XmlSerializationContext context)
        {
            int currentDepth = reader.Depth;

            while (reader.Depth < currentDepth || reader.Read())
            {
                if (reader.Depth == currentDepth)
                {
                    break;
                }
                else if (reader.Depth < currentDepth)
                {
                    return;
                }
                if (reader.NodeType == XmlNodeType.Element)
                {
                    var found = false;
                    foreach (IPropertySerializationInfo p in info.ElementProperties)
                    {
                        if (IsPropertyElement(reader, p))
                        {
                            ReadElementFromProperty(reader, obj, context, p);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        foreach (IPropertySerializationInfo p in info.AttributeProperties)
                        {
                            if (IsPropertyElement(reader, p))
                            {
                                ReadElementFromProperty(reader, obj, context, p);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            base.OnUnknownElement(new UnknownElementEventArgs(obj, reader.ReadOuterXml()));
                        }
                    }
                }
                else if ((reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA))
                {
                    if (info.DefaultProperty == null)
                    {
                        throw new InvalidOperationException("Simple content unexpected for type " + info.ToString());
                    }
                    InitializePropertyFromText(info.DefaultProperty, obj, reader.Value, context);
                }
            }
        }