private void BaseAddInternal(int index, ConfigurationElement element, bool flagAsReplaced, bool ignoreLocks)
{
element.AssociateContext(base._configRecord);
if (element != null)
{
element.CallInit();
}
if (this.IsReadOnly())
{
throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_read_only"));
}
if (!ignoreLocks)
{
if ((this.CollectionType == ConfigurationElementCollectionType.BasicMap) || (this.CollectionType == ConfigurationElementCollectionType.BasicMapAlternate))
{
if (BaseConfigurationRecord.IsReservedAttributeName(this.ElementName))
{
throw new ArgumentException(System.Configuration.SR.GetString("Basicmap_item_name_reserved", new object[] { this.ElementName }));
}
base.CheckLockedElement(this.ElementName, null);
}
if ((this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap) || (this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate))
{
base.CheckLockedElement(this._addElement, null);
}
}
if ((this.CollectionType == ConfigurationElementCollectionType.BasicMapAlternate) || (this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate))
{
if (index == -1)
{
index = (this.Count + this._removedItemCount) - this._inheritedCount;
}
else if ((index > ((this.Count + this._removedItemCount) - this._inheritedCount)) && !flagAsReplaced)
{
throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_cannot_add_items_below_inherited_items"));
}
}
if (((this.CollectionType == ConfigurationElementCollectionType.BasicMap) && (index >= 0)) && (index < this._inheritedCount))
{
throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_cannot_add_items_above_inherited_items"));
}
EntryType type = !flagAsReplaced ? EntryType.Added : EntryType.Replaced;
object elementKeyInternal = this.GetElementKeyInternal(element);
if (index >= 0)
{
if (index > this._items.Count)
{
throw new ConfigurationErrorsException(System.Configuration.SR.GetString("IndexOutOfRange", new object[] { index }));
}
this._items.Insert(index, new Entry(type, elementKeyInternal, element));
}
else
{
this._items.Add(new Entry(type, elementKeyInternal, element));
}
this.bModified = true;
}