当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationElement.AssociateContext方法代码示例

本文整理汇总了C#中System.Configuration.ConfigurationElement.AssociateContext方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationElement.AssociateContext方法的具体用法?C# ConfigurationElement.AssociateContext怎么用?C# ConfigurationElement.AssociateContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Configuration.ConfigurationElement的用法示例。


在下文中一共展示了ConfigurationElement.AssociateContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BaseAddInternal

 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:57,代码来源:ConfigurationElementCollection.cs

示例2: BaseAddInternal

        private void BaseAddInternal(int index, ConfigurationElement element, bool flagAsReplaced, bool ignoreLocks)
        {
            // Allow the element to initialize itself after its
            // constructor has been run so that it may access
            // virtual methods.

            element.AssociateContext(_configRecord);
            if (element != null)
            {
                element.CallInit();
            }

            if (IsReadOnly())
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
            }

            if (!ignoreLocks)
            { // during reset we ignore locks so we can copy the elements
                if (CollectionType == ConfigurationElementCollectionType.BasicMap ||
                    CollectionType == ConfigurationElementCollectionType.BasicMapAlternate)
                {
                    if (BaseConfigurationRecord.IsReservedAttributeName(ElementName))
                    {
                        throw new ArgumentException(SR.GetString(SR.Basicmap_item_name_reserved, ElementName));
                    }
                    CheckLockedElement(ElementName, null);
                }
                if (CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap ||
                    CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)
                {

                    CheckLockedElement(_addElement, null);
                }
            }

            if (CollectionType == ConfigurationElementCollectionType.BasicMapAlternate ||
                CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)
            {
                if (index == -1)
                {
                    index = Count + _removedItemCount - _inheritedCount; // insert before inherited, but after any removed
                }
                else
                {
                    if (index > Count + _removedItemCount - _inheritedCount && flagAsReplaced == false)
                    {
                        throw (new ConfigurationErrorsException(SR.GetString(SR.Config_base_cannot_add_items_below_inherited_items)));
                    }
                }
            }

            if (CollectionType == ConfigurationElementCollectionType.BasicMap &&
                index >= 0 &&
                index < _inheritedCount)
            {
                throw (new ConfigurationErrorsException(SR.GetString(SR.Config_base_cannot_add_items_above_inherited_items)));
            }

            EntryType entryType = (flagAsReplaced == false) ? EntryType.Added : EntryType.Replaced;

            Object key = GetElementKeyInternal(element);

            if (index >= 0)
            {
                if (index > _items.Count)
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.IndexOutOfRange, index));
                }
                _items.Insert(index, new Entry(entryType, key, element));
            }
            else
            {
                _items.Add(new Entry(entryType, key, element));
            }

            bModified = true;
        }
开发者ID:kichalla,项目名称:systemconfigurationport,代码行数:78,代码来源:ConfigurationElementCollection.cs


注:本文中的System.Configuration.ConfigurationElement.AssociateContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。