當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。