ConfigurationLockCollection 类

定义

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

public ref class ConfigurationLockCollection sealed : System::Collections::ICollection
public sealed class ConfigurationLockCollection : System.Collections.ICollection
type ConfigurationLockCollection = class
    interface ICollection
    interface IEnumerable
type ConfigurationLockCollection = class
    interface IEnumerable
    interface ICollection
Public NotInheritable Class ConfigurationLockCollection
Implements ICollection
继承
ConfigurationLockCollection
实现

示例

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

#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();
    }
  }
}
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Collections
Imports System.Text

Namespace Samples.Aspnet.SystemWebConfiguration
  Class UsingConfigurationLockCollection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = ""

        ' Get the Web application configuration object.
        Dim config As System.Configuration.Configuration = _
         WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the section related object.
        Dim configSection As _
        AnonymousIdentificationSection = _
         CType(config.GetSection("system.web/anonymousIdentification"), _
         AnonymousIdentificationSection)

        ' 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.
        Dim lockedAttribList As ConfigurationLockCollection
        lockedAttribList = configSection.LockAttributes

        ' Add an attribute to the lock collection.
        If Not (lockedAttribList.Contains("enabled")) Then
          lockedAttribList.Add("enabled")
        End If
        If Not (lockedAttribList.Contains("cookieless")) Then
          lockedAttribList.Add("cookieless")
        End If

        ' 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.
        Dim configPropertyAL As ArrayList = _
         New ArrayList(lockedAttribList.Count)
        For Each propertyItem As _
         PropertyInformation In _
         configSection.ElementInformation.Properties
          configPropertyAL.Add(propertyItem.Name.ToString())
        Next
        ' Copy the elements of the ArrayList to a string array.
        Dim myArr As [String]() = _
        CType(configPropertyAL.ToArray(GetType(String)), [String]())
        ' Create as a comma delimited list.
        Dim propList As String = String.Join(",", myArr)
        ' Lock the items in the list.
        lockedAttribList.SetFromList(propList)

      Catch e As Exception
        ' Validation failed.
        Console.WriteLine("Error: {0}", _
          e.Message.ToString())
      End Try

      ' Display and wait.
      Console.ReadLine()
    End Sub
  End Class
End Namespace

注解

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

属性

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

适用于

另请参阅