/// <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) { APGenElementCollection other = compareTo as APGenElementCollection; 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); }
internal APGenElementCollection GetDefaultCollection() { if (_defaultCollection != null) return _defaultCollection; APGenProperty defaultCollectionProp = null; foreach (APGenProperty prop in Properties) { if (prop.IsDefaultCollection) { defaultCollectionProp = prop; break; } } if (defaultCollectionProp != null) _defaultCollection = this[defaultCollectionProp] as APGenElementCollection; return _defaultCollection; }
internal APGenElementCollection GetDefaultCollection() { if (_defaultCollection != null) return _defaultCollection; APGenProperty defaultCollectionProp = null; foreach (APGenProperty prop in Properties) { if (prop.IsDefaultCollection) { defaultCollectionProp = prop; break; } } if (defaultCollectionProp != null) _defaultCollection = this[defaultCollectionProp] as APGenElementCollection; return _defaultCollection; }
/// <summary> /// Reads XML from the configuration file. /// </summary> /// <param name="reader">The XmlReader that reads from the configuration 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()) { APGenPropertyInformation 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 APGenException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, reader.LocalName), reader); } continue; } if (readProps.ContainsKey(prop)) throw new APGenException(APResource.GetString(APResource.APGen_DuplicateAttribute, prop.Name), reader); string value = null; try { value = reader.Value; ValidateValue(prop.Property, value); prop.SetStringValue(value); } catch (APGenException) { throw; } catch (Exception ex) { throw new APGenException(APResource.GetString(APResource.APGen_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; } APGenPropertyInformation prop = ElementInformation.Properties[reader.LocalName]; if (prop == null || (serializeCollectionKey && !prop.IsKey)) { if (!OnDeserializeUnrecognizedElement(reader.LocalName, reader)) { if (prop == null) { APGenElementCollection collection = GetDefaultCollection(); if (collection != null && collection.OnDeserializeUnrecognizedElement(reader.LocalName, reader)) continue; } throw new APGenException(APResource.GetString(APResource.APGen_UnrecognizedElement, reader.LocalName), reader); } continue; } if (!prop.IsElement) throw new APGenException(APResource.GetString(APResource.APGen_NotElement, prop.Name), reader); if (readProps.Contains(prop)) throw new APGenException(APResource.GetString(APResource.APGen_DuplicateElement, prop.Name), reader); APGenElement val = prop.Value as APGenElement; val.DeserializeElement(reader, serializeCollectionKey); readProps[prop] = prop.Name; } while (depth < reader.Depth); if (reader.NodeType == XmlNodeType.EndElement) reader.Read(); } foreach (APGenPropertyInformation prop in ElementInformation.Properties) { if (!String.IsNullOrEmpty(prop.Name) && prop.IsRequired && !readProps.ContainsKey(prop)) { APGenPropertyInformation property = ElementInformation.Properties[prop.Name]; if (property == null) { object val = OnRequiredPropertyNotFound(prop.Name); if (!object.Equals(val, prop.DefaultValue)) prop.Value = val; } } } PostDeserialize(); }