ConfigurationLockCollection 类

定义

包含锁定的配置对象的集合。 此类不能被继承。

C#
public sealed class ConfigurationLockCollection : System.Collections.ICollection
继承
ConfigurationLockCollection
实现

示例

下面的代码示例演示如何使用 ConfigurationLockCollection 类型。

C#
#region Using directives

using System;
using System.Configuration;
using System.Web.Configuration;
using System.Collections;
using System.Text;

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingConfigurationLockCollection
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config =
          WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        AnonymousIdentificationSection configSection =
          (AnonymousIdentificationSection)config.GetSection
          ("system.web/anonymousIdentification");

        // Display title and info.
        Console.WriteLine("Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);
        Console.WriteLine();

        // Create a ConfigurationLockCollection object.
        ConfigurationLockCollection lockedAttribList;
        lockedAttribList = configSection.LockAttributes;

        // Add an attribute to the lock collection.
        if (!lockedAttribList.Contains("enabled"))
        {
          lockedAttribList.Add("enabled");
        }
        if (!lockedAttribList.Contains("cookieless"))
        {
          lockedAttribList.Add("cookieless");
        }

        // Count property.
        Console.WriteLine("Collection Count: {0}",
         lockedAttribList.Count);

        // AttributeList method.
        Console.WriteLine("AttributeList: {0}",
         lockedAttribList.AttributeList);

        // Contains method.
        Console.WriteLine("Contains 'enabled': {0}",
         lockedAttribList.Contains("enabled"));

        // HasParentElements property.
        Console.WriteLine("HasParentElements: {0}",
         lockedAttribList.HasParentElements);

        // IsModified property.
        Console.WriteLine("IsModified: {0}",
         lockedAttribList.IsModified);

        // IsReadOnly method. 
        Console.WriteLine("IsReadOnly: {0}",
         lockedAttribList.IsReadOnly("enabled"));

        // Remove a configuration object 
        // from the collection.
        lockedAttribList.Remove("cookieless");

        // Clear the collection.
        lockedAttribList.Clear();

        // Create an ArrayList to contain
        // the property items of the configuration
        // section.
        ArrayList configPropertyAL = new ArrayList(lockedAttribList.Count);
        foreach (PropertyInformation propertyItem in
          configSection.ElementInformation.Properties)
        {
          configPropertyAL.Add(propertyItem.Name.ToString());
        }
        // Copy the elements of the ArrayList to a string array.
        String[] myArr = (String[])configPropertyAL.ToArray(typeof(string));
        // Create as a comma delimited list.
        string propList = string.Join(",", myArr);
        // Lock the items in the list.
        lockedAttribList.SetFromList(propList);
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait.
      Console.ReadLine();
    }
  }
}

注解

在配置文件中,配置节包含属性和元素。 配置 ConfigurationLockCollection 节的锁定属性存在集合,可通过 LockAttributes 类的 ConfigurationElement 属性进行访问。 另一个 ConfigurationLockCollection 集合用于配置节的锁定元素,可通过 LockElements 类的 ConfigurationElement 属性进行访问。

属性

AttributeList

获取集合中包含的配置对象的列表。

Count

获取集合中包含的锁定配置对象的数目。

HasParentElements

获取一个值,该值指定锁定对象的集合是否具有父元素。

IsModified

获取一个值,该值指定是否已修改集合。

IsSynchronized

获取一个值,该值指定集合是否已同步。

SyncRoot

获取一个对象,该对象用于同步对此 ConfigurationLockCollection 集合的访问。

方法

Add(String)

通过将配置对象添加到集合来锁定该配置对象。

Clear()

清除集合中的所有配置对象。

Contains(String)

验证是否锁定了某个特定的配置对象。

CopyTo(String[], Int32)

从目标数组的指定索引处开始,将整个 ConfigurationLockCollection 集合复制到兼容的一维 Array

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetEnumerator()

获取 IEnumerator 对象,此对象用于循环访问此 ConfigurationLockCollection 集合。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IsReadOnly(String)

验证某个特定的配置对象是否为只读。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Remove(String)

从集合中移除配置对象。

SetFromList(String)

根据所提供的列表锁定一组配置对象。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始,将整个 ConfigurationLockCollection 集合复制到兼容的一维 Array

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅