internal APXmlElementInformation(APXmlElement owner, APXmlPropertyInformation propertyInfo)
		{
			_propertyInfo = propertyInfo;
			_owner = owner;

			_properties = new APXmlPropertyInformationCollection();
			foreach (APXmlProperty prop in owner.Properties)
				_properties.Add(new APXmlPropertyInformation(owner, prop));
		}
示例#2
0
        internal APXmlElementInformation(APXmlElement owner, APXmlPropertyInformation propertyInfo)
        {
            _propertyInfo = propertyInfo;
            _owner        = owner;

            _properties = new APXmlPropertyInformationCollection();
            foreach (APXmlProperty prop in owner.Properties)
            {
                _properties.Add(new APXmlPropertyInformation(owner, prop));
            }
        }
示例#3
0
        internal override void InitFromProperty(APXmlPropertyInformation propertyInfo)
        {
            APXmlCollectionAttribute attr = propertyInfo.Property.CollectionAttribute;

            if (attr == null)
            {
                attr = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;
            }

            if (attr != null)
            {
                _addElementName = attr.AddItemName;
            }

            base.InitFromProperty(propertyInfo);
        }
示例#4
0
        /// <summary>
        /// Gets or sets a property, attribute, or child element of this element.
        /// </summary>
        /// <param name="propertyName">The name of the APXmlElementProperty to access.</param>
        /// <returns>The specified property, attribute, or child element.</returns>
        protected internal object this[string propertyName]
        {
            get
            {
                APXmlPropertyInformation property = ElementInformation.Properties[propertyName];
                if (property == null)
                {
                    throw new InvalidOperationException(APResource.GetString(APResource.APXml_PropertyNotExist, propertyName));
                }
                return(property.Value);
            }
            set
            {
                APXmlPropertyInformation property = ElementInformation.Properties[propertyName];
                if (property == null)
                {
                    throw new InvalidOperationException(APResource.GetString(APResource.APXml_PropertyNotExist, propertyName));
                }

                SetPropertyValue(property.Property, value);

                property.Value = value;
            }
        }
示例#5
0
		internal virtual void InitFromProperty(APXmlPropertyInformation propertyInfo)
		{
			_elementInfo = new APXmlElementInformation(this, propertyInfo);
			Init();
		}
		internal void Add(APXmlPropertyInformation property)
		{
			BaseAdd(property.Name, property);
		}
		/// <summary>
		/// Copies the entire APXmlPropertyInformationCollection collection to a compatible one-dimensional Array,
		/// starting at the specified index of the target array.
		/// </summary>
		/// <param name="array">A one-dimensional Array that is the destination of the elements copied from the
		/// APXmlPropertyInformationCollection collection. The Array must have zero-based indexing.</param>
		/// <param name="index">The zero-based index in array at which copying begins.</param>
		public void CopyTo(APXmlPropertyInformation[] array, int index)
		{
			((ICollection)this).CopyTo(array, index);
		}
		internal override void InitFromProperty(APXmlPropertyInformation propertyInfo)
		{
			APXmlCollectionAttribute attr = propertyInfo.Property.CollectionAttribute;
			if (attr == null)
				attr = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;

			if (attr != null)
				_addElementName = attr.AddItemName;

			base.InitFromProperty(propertyInfo);
		}
示例#9
0
 internal void Add(APXmlPropertyInformation property)
 {
     BaseAdd(property.Name, property);
 }
示例#10
0
 internal virtual void InitFromProperty(APXmlPropertyInformation propertyInfo)
 {
     _elementInfo = new APXmlElementInformation(this, propertyInfo);
     Init();
 }
示例#11
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();
        }