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)); } }
internal override void InitFromProperty(APGenPropertyInformation propertyInfo) { APGenCollectionAttribute attr = propertyInfo.Property.CollectionAttribute; if (attr == null) { attr = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; } if (attr != null) { _addElementName = attr.AddItemName; } base.InitFromProperty(propertyInfo); }
/// <summary> /// Get or set value by property name. /// </summary> /// <param name="propertyName">Property name.</param> /// <returns>Value</returns> protected internal object this[string propertyName] { get { APGenPropertyInformation property = ElementInformation.Properties[propertyName]; if (property == null) throw new InvalidOperationException(APResource.GetString(APResource.APGen_PropertyNotExist, propertyName)); return property.Value; } set { APGenPropertyInformation property = ElementInformation.Properties[propertyName]; if (property == null) throw new InvalidOperationException(APResource.GetString(APResource.APGen_PropertyNotExist, propertyName)); SetPropertyValue(property.Property, value); property.Value = value; } }
internal virtual void InitFromProperty(APGenPropertyInformation propertyInfo) { _elementInfo = new APGenElementInformation(this, propertyInfo); Init(); }
internal void Add(APGenPropertyInformation property) { BaseAdd(property.Name, property); }
/// <summary> /// Copies the entire APGenPropertyInformationCollection 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 APGenPropertyInformationCollection 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(APGenPropertyInformation[] array, int index) { ((ICollection)this).CopyTo(array, index); }
/// <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(); }
internal override void InitFromProperty(APGenPropertyInformation propertyInfo) { APGenCollectionAttribute attr = propertyInfo.Property.CollectionAttribute; if (attr == null) attr = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; if (attr != null) _addElementName = attr.AddItemName; base.InitFromProperty(propertyInfo); }