protected internal object this [string property_name] { get { PropertyInformation pi = ElementInformation.Properties [property_name]; if (pi == null) { throw new InvalidOperationException("Property '" + property_name + "' not found in configuration element"); } return(pi.Value); } set { PropertyInformation pi = ElementInformation.Properties [property_name]; if (pi == null) { throw new InvalidOperationException("Property '" + property_name + "' not found in configuration element"); } SetPropertyValue(pi.Property, value, false); pi.Value = value; modified = true; } }
protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode) { if (parentElement != null && sourceElement.GetType() != parentElement.GetType()) { throw new ConfigurationErrorsException("Can't unmerge two elements of different type"); } bool isMinimalOrModified = saveMode == ConfigurationSaveMode.Minimal || saveMode == ConfigurationSaveMode.Modified; foreach (PropertyInformation prop in sourceElement.ElementInformation.Properties) { if (prop.ValueOrigin == PropertyValueOrigin.Default) { continue; } PropertyInformation unmergedProp = ElementInformation.Properties [prop.Name]; object sourceValue = prop.Value; if (parentElement == null || !HasValue(parentElement, prop.Name)) { unmergedProp.Value = sourceValue; continue; } if (sourceValue == null) { continue; } object parentValue = GetItem(parentElement, prop.Name); if (!PropertyIsElement(prop)) { if (!object.Equals(sourceValue, parentValue) || (saveMode == ConfigurationSaveMode.Full) || (saveMode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere)) { unmergedProp.Value = sourceValue; } continue; } var sourceElem = (ConfigurationElement)sourceValue; if (isMinimalOrModified && !ElementIsModified(sourceElem)) { continue; } if (parentValue == null) { unmergedProp.Value = sourceValue; continue; } var parentElem = (ConfigurationElement)parentValue; ConfigurationElement copy = (ConfigurationElement)unmergedProp.Value; ElementUnmerge(copy, sourceElem, parentElem, saveMode); } }
public void CopyTo(PropertyInformation[] array, int index) { if (array == null) throw new ArgumentNullException(nameof(array)); if (array.Length < Count + index) throw new ArgumentOutOfRangeException(nameof(index)); foreach (PropertyInformation pi in this) array[index++] = pi; }
internal void Reset(ElementInformation parentInfo) { foreach (PropertyInformation prop in Properties) { PropertyInformation parentProp = parentInfo.Properties [prop.Name]; prop.Reset(parentProp); } }
public bool HasValue(PropertyInformation prop) { if (Mode == ConfigurationSaveMode.Full) { return(true); } return(Element.HasValue(Parent, prop, Mode)); }
internal ElementInformation (ConfigurationElement owner, PropertyInformation propertyInfo) { this.propertyInfo = propertyInfo; this.owner = owner; properties = new PropertyInformationCollection (); foreach (ConfigurationProperty prop in owner.Properties) properties.Add (new PropertyInformation (owner, prop)); }
object GetItem(ConfigurationElement element, string property) { PropertyInformation pi = ElementInformation.Properties [property]; if (pi == null) { throw new InvalidOperationException("Property '" + property + "' not found in configuration element"); } return(pi.Value); }
protected PropertyInformation get_PropertyInformation(string name) { System.Configuration. PropertyInformation propertyInformation = this.ElementInformation.Properties[name]; if (propertyInformation != null) { return(propertyInformation); } throw new ConfigurationErrorsException(string.Format("No Property with name {0} in configuration section {0}", (object)name, (object)this.SectionInformation.Name)); }
internal ElementInformation(ConfigurationElement owner, PropertyInformation propertyInfo) { this.propertyInfo = propertyInfo; this.owner = owner; properties = new PropertyInformationCollection(); foreach (ConfigurationProperty prop in owner.Properties) { properties.Add(new PropertyInformation(owner, prop)); } }
public void CopyTo(PropertyInformation[] array, int index) { if (array == null) { throw new ArgumentNullException("array"); } if (array.Length < Count + index) { throw new ArgumentOutOfRangeException("index"); } foreach (PropertyInformation pi in this) { array[index++] = pi; } }
protected internal virtual void Unmerge( ConfigurationElement source, ConfigurationElement parent, ConfigurationSaveMode updateMode) { if (parent != null && source.GetType() != parent.GetType()) { throw new ConfigurationException("Can't unmerge two elements of different type"); } foreach (PropertyInformation prop in source.ElementInformation.Properties) { if (prop.ValueOrigin == PropertyValueOrigin.Default) { continue; } PropertyInformation unmergedProp = ElementInformation.Properties [prop.Name]; object sourceValue = prop.Value; if (parent == null || !parent.HasValue(prop.Name)) { unmergedProp.Value = sourceValue; continue; } else if (sourceValue != null) { object parentValue = parent [prop.Name]; if (prop.IsElement) { if (parentValue != null) { ConfigurationElement copy = (ConfigurationElement)unmergedProp.Value; copy.Unmerge((ConfigurationElement)sourceValue, (ConfigurationElement)parentValue, updateMode); } else { unmergedProp.Value = sourceValue; } } else { if (!object.Equals(sourceValue, parentValue) || (updateMode == ConfigurationSaveMode.Full) || (updateMode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere)) { unmergedProp.Value = sourceValue; } } } } }
internal override void InitFromProperty (PropertyInformation propertyInfo) { ConfigurationCollectionAttribute colat = propertyInfo.Property.CollectionAttribute; if (colat == null) colat = Attribute.GetCustomAttribute (propertyInfo.Type, typeof (ConfigurationCollectionAttribute)) as ConfigurationCollectionAttribute; if (colat != null) { addElementName = colat.AddItemName; clearElementName = colat.ClearItemsName; removeElementName = colat.RemoveItemName; } base.InitFromProperty (propertyInfo); }
public PropertyInformation this[string propertyName] { get { PropertyInformation information = (PropertyInformation)base.BaseGet(propertyName); if (information == null) { PropertyInformation information2 = (PropertyInformation)base.BaseGet(ConfigurationProperty.DefaultCollectionPropertyName); if ((information2 != null) && (information2.ProvidedName == propertyName)) { information = information2; } } return(information); } }
internal override void InitFromProperty(PropertyInformation propertyInfo) { ConfigurationCollectionAttribute colat = propertyInfo.Property.CollectionAttribute; if (colat == null) { colat = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(ConfigurationCollectionAttribute)) as ConfigurationCollectionAttribute; } if (colat != null) { addElementName = colat.AddItemName; clearElementName = colat.ClearItemsName; removeElementName = colat.RemoveItemName; } base.InitFromProperty(propertyInfo); }
// Item // // Indexor for retrieving a Property by name // public PropertyInformation this[string propertyName] { get { PropertyInformation result = (PropertyInformation)BaseGet(propertyName); // check for default collection name if (result == null) { PropertyInformation defaultColl = (PropertyInformation)BaseGet(ConfigurationProperty.DefaultCollectionPropertyName); if ((defaultColl != null) && (defaultColl.ProvidedName == propertyName)) { result = defaultColl; } } return(result); } }
internal void Reset(PropertyInformation parentProperty) { if (parentProperty != null) { if (property.IsElement) { ((ConfigurationElement)Value).Reset((ConfigurationElement)parentProperty.Value); } else { val = parentProperty.Value; origin = PropertyValueOrigin.Inherited; } } else { origin = PropertyValueOrigin.Default; } }
///<summary> /// Initializes an instance of ElementProperty. ///</summary> ///<param name="serviceProvider">Service provider used to locate certain services for the configuration system.</param> ///<param name="parent">The parent <see cref="ElementViewModel"/> owning the property.</param> ///<param name="declaringProperty">The description of the property.</param> ///<param name="additionalAttributes">Additional attributes made available to the ElementProperty.</param> ///<exception cref="ArgumentNullException"></exception> public ElementProperty(IServiceProvider serviceProvider, ElementViewModel parent, PropertyDescriptor declaringProperty, IEnumerable<Attribute> additionalAttributes) : base(serviceProvider, parent == null ? null : parent.ConfigurationElement, declaringProperty, additionalAttributes) { if (parent == null) throw new ArgumentNullException("parent"); declaringElement = parent; ConfigurationElement parentElement = parent.ConfigurationElement; configurationPropertyAttribute = declaringProperty.Attributes.OfType<ConfigurationPropertyAttribute>().FirstOrDefault(); if (configurationPropertyAttribute == null) { configurationPropertyAttribute = additionalAttributes.OfType<ConfigurationPropertyAttribute>().FirstOrDefault(); } if (configurationPropertyAttribute != null) { configurationProperty = parentElement.ElementInformation.Properties[configurationPropertyAttribute.Name]; } this.declaringElement.PropertyChanged += DeclaringElementPropertyChanged; }
protected override void PostDeserialize() { if (!base.EvaluationContext.IsMachineLevel) { PropertyInformation[] informationArray = new PropertyInformation[] { base.ElementInformation.Properties["checkCertificateName"], base.ElementInformation.Properties["checkCertificateRevocationList"] }; foreach (PropertyInformation information in informationArray) { if (information.ValueOrigin == PropertyValueOrigin.SetHere) { try { ExceptionHelper.UnmanagedPermission.Demand(); } catch (Exception exception) { throw new ConfigurationErrorsException(System.SR.GetString("net_config_property_permission", new object[] { information.Name }), exception); } } } } }
/* * FIXME: LAMESPEC * * SerializeElement() and SerializeToXmlElement() need to emit different output * based on the ConfigurationSaveMode that's being used. Unfortunately, neither * of these methods take it as an argument and there seems to be no documented way * how to get it. * * The parent element is needed because the element could be set to a different * than the default value in a parent configuration file, then set locally to that * same value. This makes the element appear locally modified (so it's included * with ConfigurationSaveMode.Modified), but it should not be emitted with * ConfigurationSaveMode.Minimal. * * In theory, we could save it into some private field in Unmerge(), but the * problem is that Unmerge() is kinda expensive and we also need a way of * determining whether or not the configuration has changed in Configuration.Save(), * prior to opening the output file for writing. * * There are two places from where HasValues() is called: * a) From Configuration.Save() / SaveAs() to check whether the configuration needs * to be saved. This check is done prior to opening the file for writing. * b) From SerializeToXmlElement() to check whether to emit the element, using the * parent and mode values from the cached 'SaveContext'. * */ /* * Check whether property 'prop' should be included in the serialized XML * based on the current ConfigurationSaveMode. */ internal bool HasValue(ConfigurationElement parent, PropertyInformation prop, ConfigurationSaveMode mode) { if (prop.ValueOrigin == PropertyValueOrigin.Default) { return(false); } if (mode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere && prop.IsModified) { // Value has been modified locally, so we always emit it // with ConfigurationSaveMode.Modified. return(true); } /* * Ok, now we have to check whether we're different from the inherited * value - which could either be a value that's set in a parent * configuration file or the default value. */ var hasParentValue = parent != null && parent.HasValue(prop.Name); var parentOrDefault = hasParentValue ? parent [prop.Name] : prop.DefaultValue; if (!prop.IsElement) { return(!object.Equals(prop.Value, parentOrDefault)); } /* * Ok, it's an element that has been set in a parent configuration file. * * Recursively call HasValues() to check whether it's been locally modified. */ var element = (ConfigurationElement)prop.Value; var parentElement = (ConfigurationElement)parentOrDefault; return(element.HasValues(parentElement, mode)); }
internal void Add (PropertyInformation pi) { BaseAdd (pi.Name, pi); }
internal virtual void InitFromProperty (PropertyInformation propertyInfo) { elementInfo = new ElementInformation (this, propertyInfo); Init (); }
bool PropertyIsElement(PropertyInformation prop) { return(typeof(ConfigurationElement).IsAssignableFrom(prop.Type)); }
/* * FIXME: LAMESPEC * * SerializeElement() and SerializeToXmlElement() need to emit different output * based on the ConfigurationSaveMode that's being used. Unfortunately, neither * of these methods take it as an argument and there seems to be no documented way * how to get it. * * The parent element is needed because the element could be set to a different * than the default value in a parent configuration file, then set locally to that * same value. This makes the element appear locally modified (so it's included * with ConfigurationSaveMode.Modified), but it should not be emitted with * ConfigurationSaveMode.Minimal. * * In theory, we could save it into some private field in Unmerge(), but the * problem is that Unmerge() is kinda expensive and we also need a way of * determining whether or not the configuration has changed in Configuration.Save(), * prior to opening the output file for writing. * * There are two places from where HasValues() is called: * a) From Configuration.Save() / SaveAs() to check whether the configuration needs * to be saved. This check is done prior to opening the file for writing. * b) From SerializeToXmlElement() to check whether to emit the element, using the * parent and mode values from the cached 'SaveContext'. * */ /* * Check whether property 'prop' should be included in the serialized XML * based on the current ConfigurationSaveMode. */ internal bool HasValue (ConfigurationElement parent, PropertyInformation prop, ConfigurationSaveMode mode) { if (prop.ValueOrigin == PropertyValueOrigin.Default) return false; if (mode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere && prop.IsModified) { // Value has been modified locally, so we always emit it // with ConfigurationSaveMode.Modified. return true; } /* * Ok, now we have to check whether we're different from the inherited * value - which could either be a value that's set in a parent * configuration file or the default value. */ var hasParentValue = parent != null && parent.HasValue (prop.Name); var parentOrDefault = hasParentValue ? parent [prop.Name] : prop.DefaultValue; if (!prop.IsElement) return !object.Equals (prop.Value, parentOrDefault); /* * Ok, it's an element that has been set in a parent configuration file. * * Recursively call HasValues() to check whether it's been locally modified. */ var element = (ConfigurationElement) prop.Value; var parentElement = (ConfigurationElement) parentOrDefault; return element.HasValues (parentElement, mode); }
bool HasValue(ConfigurationElement element, string propName) { PropertyInformation info = element.ElementInformation.Properties [propName]; return(info != null && info.ValueOrigin != PropertyValueOrigin.Default); }
public void CopyTo(PropertyInformation[] array, int index) { Contract.Requires(array != null); Contract.Requires(index >= 0); }
internal void Add(PropertyInformation pi) { BaseAdd(pi.Name, pi); }
internal bool HasValue(string propName) { PropertyInformation info = ElementInformation.Properties [propName]; return(info != null && info.ValueOrigin != PropertyValueOrigin.Default); }
internal bool IsReadFromConfig(string propName) { PropertyInformation info = ElementInformation.Properties [propName]; return(info != null && info.ValueOrigin == PropertyValueOrigin.SetHere); }
internal virtual void InitFromProperty(PropertyInformation propertyInfo) { elementInfo = new ElementInformation(this, propertyInfo); Init(); }
protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { Hashtable readProps = new Hashtable(); reader.MoveToContent(); elementPresent = true; while (reader.MoveToNextAttribute()) { PropertyInformation prop = ElementInformation.Properties [reader.LocalName]; if (prop == null || (serializeCollectionKey && !prop.IsKey)) { /* handle the built in ConfigurationElement attributes here */ if (reader.LocalName == "lockAllAttributesExcept") { LockAllAttributesExcept.SetFromList(reader.Value); } else if (reader.LocalName == "lockAllElementsExcept") { LockAllElementsExcept.SetFromList(reader.Value); } else if (reader.LocalName == "lockAttributes") { LockAttributes.SetFromList(reader.Value); } else if (reader.LocalName == "lockElements") { LockElements.SetFromList(reader.Value); } else if (reader.LocalName == "lockItem") { LockItem = (reader.Value.ToLowerInvariant() == "true"); } else if (reader.LocalName == "xmlns") { /* ignore */ } else if (this is ConfigurationSection && reader.LocalName == "configSource") { /* ignore */ } else if (!OnDeserializeUnrecognizedAttribute(reader.LocalName, reader.Value)) { throw new ConfigurationErrorsException("Unrecognized attribute '" + reader.LocalName + "'.", reader); } continue; } if (readProps.ContainsKey(prop)) { throw new ConfigurationErrorsException("The attribute '" + prop.Name + "' may only appear once in this element.", reader); } string value = null; try { value = reader.Value; ValidateValue(prop.Property, value); prop.SetStringValue(value); } catch (ConfigurationErrorsException) { throw; } catch (ConfigurationException) { throw; } catch (Exception ex) { string msg = String.Format("The value for the property '{0}' is not valid. The error is: {1}", prop.Name, ex.Message); throw new ConfigurationErrorsException(msg, reader); } readProps [prop] = prop.Name; ConfigXmlTextReader _reader = reader as ConfigXmlTextReader; if (_reader != null) { prop.Source = _reader.Filename; prop.LineNumber = _reader.LineNumber; } } 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; } PropertyInformation prop = ElementInformation.Properties [reader.LocalName]; if (prop == null || (serializeCollectionKey && !prop.IsKey)) { if (!OnDeserializeUnrecognizedElement(reader.LocalName, reader)) { if (prop == null) { ConfigurationElementCollection c = GetDefaultCollection(); if (c != null && c.OnDeserializeUnrecognizedElement(reader.LocalName, reader)) { continue; } } throw new ConfigurationErrorsException("Unrecognized element '" + reader.LocalName + "'.", reader); } continue; } if (!prop.IsElement) { throw new ConfigurationErrorsException("Property '" + prop.Name + "' is not a ConfigurationElement."); } if (readProps.Contains(prop)) { throw new ConfigurationErrorsException("The element <" + prop.Name + "> may only appear once in this section.", reader); } ConfigurationElement val = (ConfigurationElement)prop.Value; val.DeserializeElement(reader, serializeCollectionKey); readProps [prop] = prop.Name; if (depth == reader.Depth) { reader.Read(); } } while (depth < reader.Depth); } modified = false; foreach (PropertyInformation prop in ElementInformation.Properties) { if (!String.IsNullOrEmpty(prop.Name) && prop.IsRequired && !readProps.ContainsKey(prop)) { PropertyInformation p = ElementInformation.Properties [prop.Name]; if (p == null) { object val = OnRequiredPropertyNotFound(prop.Name); if (!object.Equals(val, prop.DefaultValue)) { prop.Value = val; prop.IsModified = false; } } } } PostDeserialize(); }
private static bool ShouldOverrideLocalProperty(PropertyInformation localProperty, PropertyInformation parentProperty) { return (localProperty.ValueOrigin == PropertyValueOrigin.Default); }
public void CopyTo (PropertyInformation[] array, int index) { ((ICollection)this).CopyTo (array, index); }
internal static ConfigurationErrorsException MakeConfigurationErrorsException(string message, Exception innerException = null, PropertyInformation configProperty = null) { return new ConfigurationErrorsException(message, innerException, (configProperty != null) ? configProperty.Source : null, (configProperty != null) ? configProperty.LineNumber : 0); }
bool PropertyIsElement (PropertyInformation prop) { return (typeof(ConfigurationElement).IsAssignableFrom (prop.Type)); }
public bool HasValue (PropertyInformation prop) { if (Mode == ConfigurationSaveMode.Full) return true; return Element.HasValue (Parent, prop, Mode); }
internal void Reset (PropertyInformation parentProperty) { if (parentProperty != null) { if (property.IsElement) { ((ConfigurationElement)Value).Reset ((ConfigurationElement) parentProperty.Value); } else { val = parentProperty.Value; origin = PropertyValueOrigin.Inherited; } } else { origin = PropertyValueOrigin.Default; } }
public void CopyTo(PropertyInformation[] array, int index) { Contract.Ensures((Contract.OldValue(index) - array.Length) <= 0); Contract.Ensures((this.Count - array.Length) <= 0); Contract.Ensures(0 <= this.Count); }