namespace System.Configuration
{
[DebuggerDisplayAttribute ("Count = {Count}")]
- public abstract class ConfigurationElementCollection : ConfigurationElement, ICollection, IEnumerable
+ public abstract partial class ConfigurationElementCollection : ConfigurationElement, ICollection, IEnumerable
{
ArrayList list = new ArrayList ();
ArrayList removed;
internal override void InitFromProperty (PropertyInformation propertyInfo)
{
ConfigurationCollectionAttribute colat = propertyInfo.Property.CollectionAttribute;
+
if (colat == null)
- colat = ElementMap.GetMap (GetType ()).CollectionAttribute;
+ colat = Attribute.GetCustomAttribute (propertyInfo.Type, typeof (ConfigurationCollectionAttribute)) as ConfigurationCollectionAttribute;
+
if (colat != null) {
addElementName = colat.AddItemName;
clearElementName = colat.ClearItemsName;
#region Properties
- protected virtual ConfigurationElementCollectionType CollectionType {
+ public virtual ConfigurationElementCollectionType CollectionType {
get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
}
}
}
- public virtual int Count {
+ public int Count {
get { return list.Count; }
}
}
protected virtual bool ThrowOnDuplicate {
- get { return true; }
+ get {
+ if (CollectionType != ConfigurationElementCollectionType.AddRemoveClearMap &&
+ CollectionType != ConfigurationElementCollectionType.AddRemoveClearMapAlternate)
+ return false;
+
+ return true;
+ }
}
protected internal string AddElementName {
BaseAdd (element, ThrowOnDuplicate);
}
- protected virtual void BaseAdd (ConfigurationElement element, bool throwIfExists)
+ protected void BaseAdd (ConfigurationElement element, bool throwIfExists)
{
-// if (throwIfExists && BaseIndexOf (element) != -1)
-// throw new ConfigurationException ("Duplicate element in collection");
if (IsReadOnly ())
throw new ConfigurationErrorsException ("Collection is read only.");
list.Insert (inheritedLimitIndex, element);
inheritedLimitIndex++;
}
- else
+ else {
+ int old_index = IndexOfKey (GetElementKey (element));
+ if (old_index >= 0) {
+ if (element.Equals (list [old_index]))
+ return;
+ if (throwIfExists)
+ throw new ConfigurationException ("Duplicate element in collection");
+ list.RemoveAt (old_index);
+ }
list.Add (element);
+ }
+
modified = true;
}
protected virtual void BaseAdd (int index, ConfigurationElement element)
{
-// if (ThrowOnDuplicate && BaseIndexOf (element) != -1)
-// throw new ConfigurationException ("Duplicate element in collection");
+ if (ThrowOnDuplicate && BaseIndexOf (element) != -1)
+ throw new ConfigurationException ("Duplicate element in collection");
if (IsReadOnly ())
throw new ConfigurationErrorsException ("Collection is read only.");
throw new ConfigurationErrorsException ("Can't insert new elements below the inherited elements.");
if (!IsAlternate && (index <= inheritedLimitIndex))
throw new ConfigurationErrorsException ("Can't insert new elements above the inherited elements.");
-
+
list.Insert (index, element);
modified = true;
}
protected internal object BaseGetKey (int index)
{
+ if (index < 0 || index >= list.Count)
+ throw new ConfigurationErrorsException (String.Format ("Index {0} is out of range", index));
+
return GetElementKey ((ConfigurationElement) list[index]).ToString ();
}
return modified;
}
+ [MonoTODO]
+ public override bool IsReadOnly ()
+ {
+ return base.IsReadOnly ();
+ }
+
internal override bool HasValues ()
{
return list.Count > 0;
for (int n=0; n<parent.Count; n++)
{
ConfigurationElement parentItem = parent.BaseGet (n);
- ConfigurationElement item = CreateNewElementInternal (parentItem.GetType().FullName);
+ ConfigurationElement item = CreateNewElementInternal (null);
item.Reset (parentItem);
BaseAdd (item);
modified = false;
}
+ [MonoTODO]
+ protected internal override void SetReadOnly ()
+ {
+ base.SetReadOnly ();
+ }
+
protected internal override bool SerializeElement (XmlWriter writer, bool serializeCollectionKey)
{
if (serializeCollectionKey) {
}
else {
if (elementName == clearElementName) {
- ConfigurationElement elem = CreateNewElementInternal (null);
- elem.DeserializeElement (reader, true);
+ reader.MoveToContent ();
+ if (reader.MoveToNextAttribute ())
+ throw new ConfigurationErrorsException ("Unrecognized attribute '" + reader.LocalName + "'.");
+ reader.MoveToElement ();
+ reader.Skip ();
BaseClear ();
emitClear = true;
modified = false;
}
else if (elementName == removeElementName) {
ConfigurationElement elem = CreateNewElementInternal (null);
- elem.DeserializeElement (reader, true);
- BaseRemove (GetElementKey (elem));
+ ConfigurationRemoveElement removeElem = new ConfigurationRemoveElement (elem, this);
+ removeElem.DeserializeElement (reader, true);
+ BaseRemove (removeElem.KeyValue);
modified = false;
return true;
}
object key = source.GetElementKey (sitem);
ConfigurationElement pitem = parent != null ? parent.BaseGet (key) as ConfigurationElement : null;
if (pitem != null && updateMode != ConfigurationSaveMode.Full) {
- ConfigurationElement nitem = CreateNewElementInternal (pitem.GetType().FullName);
+ ConfigurationElement nitem = CreateNewElementInternal (null);
nitem.Unmerge (sitem, pitem, ConfigurationSaveMode.Minimal);
if (nitem.HasValues ())
BaseAdd (nitem);
}
else {
- ConfigurationElement nitem = CreateNewElementInternal (sitem.GetType().FullName);
+ ConfigurationElement nitem = CreateNewElementInternal (null);
nitem.Unmerge (sitem, null, ConfigurationSaveMode.Full);
BaseAdd (nitem);
}