private APGenElement CreateElement(Type type) { APGenElement element = Activator.CreateInstance(type) as APGenElement; element.Init(); return(element); }
/// <summary> /// Adds a configuration element to the configuration element collection. /// </summary> /// <param name="index">The index location at which to add the specified APGenElement.</param> /// <param name="element">The APGenElement to add.</param> protected virtual void BaseAdd(int index, APGenElement element) { if (ThrowOnDuplicate && BaseIndexOf(element) != -1) { throw new APGenException(APResource.APGen_DuplicateElementInCollection); } _list.Insert(index, element); }
internal APGenElementInformation(APGenElement owner, APGenPropertyInformation propertyInfo) { _propertyInfo = propertyInfo; _owner = owner; _properties = new APGenPropertyInformationCollection(); foreach (APGenProperty prop in owner.Properties) _properties.Add(new APGenPropertyInformation(owner, prop)); }
internal APGenElementInformation(APGenElement owner, APGenPropertyInformation propertyInfo) { _propertyInfo = propertyInfo; _owner = owner; _properties = new APGenPropertyInformationCollection(); foreach (APGenProperty prop in owner.Properties) { _properties.Add(new APGenPropertyInformation(owner, prop)); } }
/// <summary> /// Causes the configuration system to throw an exception. /// </summary> /// <param name="elementName">The name of the unrecognized element.</param> /// <param name="reader">An input stream that reads XML from the configuration file.</param> /// <returns>true if the unrecognized element was deserialized successfully; otherwise, false. The default is false.</returns> protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader) { if (elementName == _addElementName) { APGenElement elem = CreateNewElementInternal(null); elem.DeserializeElement(reader, false); BaseAdd(elem); return(true); } return(false); }
/// <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) { APGenElement other = compareTo as APGenElement; if (other == null) return false; if (GetType() != other.GetType()) return false; foreach (APGenProperty prop in Properties) { if (!object.Equals(this[prop], other[prop])) return false; } return true; }
/// <summary> /// Adds a configuration element to the configuration element collection. /// </summary> /// <param name="element">The APGenElement to add.</param> /// <param name="throwIfExists">true to throw an exception if the APGenElement specified is already contained /// in the collection; otherwise, false.</param> protected void BaseAdd(APGenElement element, bool throwIfExists) { int oldIndex = IndexOfKey(GetElementKey(element)); if (oldIndex >= 0) { if (element.Equals(_list[oldIndex])) { return; } if (throwIfExists) { throw new APGenException(APResource.APGen_DuplicateElementInCollection); } _list.RemoveAt(oldIndex); } _list.Add(element); }
/// <summary> /// Writes the configuration data to an XML element in the configuration file when overridden in a derived class. /// </summary> /// <param name="writer">Output stream that writes XML to the configuration file.</param> /// <param name="serializeCollectionKey">true to serialize the collection key; otherwise, false.</param> /// <returns>true if the collection was written to the configuration file successfully.</returns> protected internal override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey) { if (serializeCollectionKey) { return(base.SerializeElement(writer, serializeCollectionKey)); } bool wroteData = false; for (int i = 0; i < _list.Count; i++) { APGenElement elem = (APGenElement)_list[i]; elem.SerializeToXmlElement(writer, _addElementName); } wroteData = wroteData || _list.Count > 0; return(wroteData); }
/// <summary> /// Writes the contents of this configuration element to the configuration file when implemented in a derived class. /// </summary> /// <param name="writer">The XmlWriter that writes to the configuration file.</param> /// <param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param> /// <returns>true if any data was actually serialized; otherwise, false.</returns> protected internal virtual bool SerializeElement(XmlWriter writer, bool serializeCollectionKey) { PreSerialize(writer); if (serializeCollectionKey) { APGenPropertyCollection props = GetKeyProperties(); foreach (APGenProperty prop in props) writer.WriteAttributeString(prop.Name, prop.ConvertToString(this[prop.Name])); return props.Count > 0; } bool wroteData = false; foreach (APGenPropertyInformation prop in ElementInformation.Properties) { if (prop.IsElement || prop.ValueOrigin == APGenPropertyValueOrigin.Default) continue; if (!object.Equals(prop.Value, prop.DefaultValue)) { writer.WriteAttributeString(prop.Name, prop.GetStringValue()); wroteData = true; } } foreach (APGenPropertyInformation prop in ElementInformation.Properties) { if (!prop.IsElement) continue; APGenElement val = prop.Value as APGenElement; if (val != null) wroteData = val.SerializeToXmlElement(writer, prop.Name) || wroteData; } return wroteData; }
/// <summary> /// The index of the specified APGenElement. /// </summary> /// <param name="element">The APGenElement for the specified index location.</param> /// <returns>The index of the specified APGenElement; otherwise, -1.</returns> protected int BaseIndexOf(APGenElement element) { return(_list.IndexOf(element)); }
/// <summary> /// Adds a configuration element to the configuration element collection. /// </summary> /// <param name="element">The APGenElement to add.</param> protected virtual void BaseAdd(APGenElement element) { BaseAdd(element, ThrowOnDuplicate); }
/// <summary> /// Adds a configuration element to the configuration element collection. /// </summary> /// <param name="element">The APGenElement to add.</param> protected virtual void BaseAdd(APGenElement element) { BaseAdd(element, ThrowOnDuplicate); }
/// <summary> /// Gets the element key for a specified configuration element. /// </summary> /// <param name="element">The ConfigurationElement to return the key for.</param> /// <returns>An Object that acts as the key for the specified ConfigurationElement.</returns> protected override object GetElementKey(APGenElement element) { return ((NameValueAPGenElement)element).Name; }
/// <summary> /// The index of the specified APGenElement. /// </summary> /// <param name="element">The APGenElement for the specified index location.</param> /// <returns>The index of the specified APGenElement; otherwise, -1.</returns> protected int BaseIndexOf(APGenElement element) { return _list.IndexOf(element); }
/// <summary> /// Gets the element key for a specified configuration element. /// </summary> /// <param name="element">The ConfigurationElement to return the key for.</param> /// <returns>An Object that acts as the key for the specified ConfigurationElement.</returns> protected override object GetElementKey(APGenElement element) { return(((NameValueAPGenElement)element).Name); }
/// <summary> /// Adds a configuration element to the configuration element collection. /// </summary> /// <param name="element">The APGenElement to add.</param> /// <param name="throwIfExists">true to throw an exception if the APGenElement specified is already contained /// in the collection; otherwise, false.</param> protected void BaseAdd(APGenElement element, bool throwIfExists) { int oldIndex = IndexOfKey(GetElementKey(element)); if (oldIndex >= 0) { if (element.Equals(_list[oldIndex])) return; if (throwIfExists) throw new APGenException(APResource.APGen_DuplicateElementInCollection); _list.RemoveAt(oldIndex); } _list.Add(element); }
/// <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(); }
/// <summary> /// Copies the entire collection values to a one-dimensional array of strings, starting at /// the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional array of strings that is the destination of the /// elements copied from 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(APGenElement[] array, int index) { _list.CopyTo(array, index); }
/// <summary> /// Gets the element key for a specified configuration element when overridden in a derived class. /// </summary> /// <param name="element">The APGenElement to return the key for.</param> /// <returns>An Object that acts as the key for the specified APGenElement.</returns> protected abstract object GetElementKey(APGenElement element);
/// <summary> /// Removes the APGenElement at the specified index location. /// </summary> /// <param name="index">The index location of the APGenElement to remove.</param> protected internal void BaseRemoveAt(int index) { APGenElement elem = (APGenElement)_list[index]; _list.RemoveAt(index); }
/// <summary> /// Gets the element key for a specified configuration element when overridden in a derived class. /// </summary> /// <param name="element">The APGenElement to return the key for.</param> /// <returns>An Object that acts as the key for the specified APGenElement.</returns> protected abstract object GetElementKey(APGenElement element);
internal APGenPropertyInformation(APGenElement owner, APGenProperty property) { _owner = owner; _property = property; }
internal APGenPropertyInformation(APGenElement owner, APGenProperty property) { _owner = owner; _property = property; }
/// <summary> /// Adds a configuration element to the configuration element collection. /// </summary> /// <param name="index">The index location at which to add the specified APGenElement.</param> /// <param name="element">The APGenElement to add.</param> protected virtual void BaseAdd(int index, APGenElement element) { if (ThrowOnDuplicate && BaseIndexOf(element) != -1) throw new APGenException(APResource.APGen_DuplicateElementInCollection); _list.Insert(index, element); }