示例#1
0
        /// <summary>
        /// Determines whether two Object instances are equal.
        /// </summary>
        /// <param name="compareTo">The Object to compare with the current Object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object compareTo)
        {
            APXmlElementCollection other = compareTo as APXmlElementCollection;

            if (other == null)
            {
                return(false);
            }

            if (GetType() != other.GetType())
            {
                return(false);
            }

            if (Count != other.Count)
            {
                return(false);
            }

            for (int i = 0; i < Count; i++)
            {
                if (!BaseGet(i).Equals(other.BaseGet(i)))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        internal APXmlElementCollection GetDefaultCollection()
        {
            if (_defaultCollection != null)
            {
                return(_defaultCollection);
            }

            APXmlProperty defaultCollectionProp = null;

            foreach (APXmlProperty prop in Properties)
            {
                if (prop.IsDefaultCollection)
                {
                    defaultCollectionProp = prop;
                    break;
                }
            }

            if (defaultCollectionProp != null)
            {
                _defaultCollection = this[defaultCollectionProp] as APXmlElementCollection;
            }
            return(_defaultCollection);
        }
示例#3
0
		internal APXmlElementCollection GetDefaultCollection()
		{
			if (_defaultCollection != null)
				return _defaultCollection;

			APXmlProperty defaultCollectionProp = null;

			foreach (APXmlProperty prop in Properties)
			{
				if (prop.IsDefaultCollection)
				{
					defaultCollectionProp = prop;
					break;
				}
			}

			if (defaultCollectionProp != null)
				_defaultCollection = this[defaultCollectionProp] as APXmlElementCollection;
			return _defaultCollection;
		}
示例#4
0
        /// <summary>
        /// Reads XML from the xml file.
        /// </summary>
        /// <param name="reader">The XmlReader that reads from the xml file.</param>
        /// <param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param>
        protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            Hashtable readProps = new Hashtable();

            reader.MoveToContent();

            while (reader.MoveToNextAttribute())
            {
                APXmlPropertyInformation prop = ElementInformation.Properties[reader.LocalName];
                if (prop == null || (serializeCollectionKey && !prop.IsKey))
                {
                    if (reader.LocalName == "xmlns")
                    {
                        // Ignore
                    }
                    else if (!OnDeserializeUnrecognizedAttribute(reader.LocalName, reader.Value))
                    {
                        throw new APXmlException(APResource.GetString(APResource.APXml_UnrecognizedAttribute, reader.LocalName));
                    }

                    continue;
                }

                if (readProps.ContainsKey(prop))
                {
                    throw new APXmlException(APResource.GetString(APResource.APXml_DuplicateAttribute, prop.Name));
                }

                string value = null;
                try
                {
                    value = reader.Value;
                    ValidateValue(prop.Property, value);
                    prop.SetStringValue(value);
                }
                catch (APXmlException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new APXmlException(APResource.GetString(APResource.APXml_PropertyCannotBeParsed, prop.Name), ex, reader);
                }
                readProps[prop] = prop.Name;
            }

            reader.MoveToElement();

            if (reader.IsEmptyElement)
            {
                reader.Skip();
            }
            else
            {
                int depth = reader.Depth;

                reader.ReadStartElement();
                reader.MoveToContent();

                do
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        reader.Skip();
                        continue;
                    }

                    APXmlPropertyInformation prop = ElementInformation.Properties[reader.LocalName];
                    if (prop == null || (serializeCollectionKey && !prop.IsKey))
                    {
                        if (!OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                        {
                            if (prop == null)
                            {
                                APXmlElementCollection collection = GetDefaultCollection();
                                if (collection != null && collection.OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                                {
                                    continue;
                                }
                            }
                            throw new APXmlException(APResource.GetString(APResource.APXml_UnrecognizedElement, reader.LocalName));
                        }
                        continue;
                    }

                    if (!prop.IsElement)
                    {
                        throw new APXmlException(APResource.GetString(APResource.APXml_NotAElement, prop.Name));
                    }

                    if (readProps.Contains(prop))
                    {
                        throw new APXmlException(APResource.GetString(APResource.APXml_DuplicateElement, prop.Name));
                    }

                    APXmlElement val = prop.Value as APXmlElement;
                    val.DeserializeElement(reader, serializeCollectionKey);
                    readProps[prop] = prop.Name;
                } while (depth < reader.Depth);

                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.Read();
                }
            }

            foreach (APXmlPropertyInformation prop in ElementInformation.Properties)
            {
                if (!String.IsNullOrEmpty(prop.Name) && prop.IsRequired && !readProps.ContainsKey(prop))
                {
                    APXmlPropertyInformation property = ElementInformation.Properties[prop.Name];
                    if (property == null)
                    {
                        object val = OnRequiredPropertyNotFound(prop.Name);
                        if (!object.Equals(val, prop.DefaultValue))
                        {
                            prop.Value = val;
                        }
                    }
                }
            }

            PostDeserialize();
        }