System.Configuration.ProviderSettingsCollection 类

方法描述

表示 ProviderSettings 对象的集合。

语法定义(C# System.Configuration.ProviderSettingsCollection 类 的用法)

[ConfigurationCollectionAttribute(typeof(ProviderSettings))]
public sealed class ProviderSettingsCollection : ConfigurationElementCollection

构造函数

构造函数名称 构造函数描述
ProviderSettingsCollection 初始化 ProviderSettingsCollection 类的新实例。

成员/方法

方法名称 方法描述
Add 将 ProviderSettings 对象添加到集合中。
BaseAdd(ConfigurationElement) 向 ConfigurationElementCollection 添加配置元素。 (继承自 ConfigurationElementCollection。)
BaseAdd(ConfigurationElement, Boolean) 向配置元素集合添加配置元素。 (继承自 ConfigurationElementCollection。)
BaseAdd(Int32, ConfigurationElement) 向配置元素集合添加配置元素。 (继承自 ConfigurationElementCollection。)
BaseClear 从集合中移除所有配置元素对象。 (继承自 ConfigurationElementCollection。)
BaseGet(Int32) 获取位于指定索引位置的配置元素。 (继承自 ConfigurationElementCollection。)
BaseGet(Object) 返回具有指定键的配置元素。 (继承自 ConfigurationElementCollection。)
BaseGetAllKeys 返回 ConfigurationElementCollection 中包含的所有配置元素的键数组。 (继承自 ConfigurationElementCollection。)
BaseGetKey 获取位于指定索引位置的 ConfigurationElement 的键。 (继承自 ConfigurationElementCollection。)
BaseIndexOf 指定 ConfigurationElement 的索引。 (继承自 ConfigurationElementCollection。)
BaseIsRemoved 获取一个值,该值指示是否已从 ConfigurationElementCollection 中移除具有指定键的 ConfigurationElement。 (继承自 ConfigurationElementCollection。)
BaseRemove 从集合中移除 ConfigurationElement。 (继承自 ConfigurationElementCollection。)
BaseRemoveAt 移除位于指定索引位置的 ConfigurationElement。 (继承自 ConfigurationElementCollection。)
Clear 清除集合。
CopyTo 将 ConfigurationElementCollection 的内容复制到数组。 (继承自 ConfigurationElementCollection。)
CreateNewElement() 当在派生的类中重写时,创建一个新的 ConfigurationElement。 (继承自 ConfigurationElementCollection。)
CreateNewElement(String) 在派生的类中重写时,创建新的 ConfigurationElement。 (继承自 ConfigurationElementCollection。)
DeserializeElement 读取配置文件中的 XML。 (继承自 ConfigurationElement。)
Equals 将 ConfigurationElementCollection 与指定的对象进行比较。 (继承自 ConfigurationElementCollection。)
Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
GetElementKey 在派生类中重写时获取指定配置元素的元素键。 (继承自 ConfigurationElementCollection。)
GetEnumerator 基础结构。获取用于循环访问 ConfigurationElementCollection 的 IEnumerator。 (继承自 ConfigurationElementCollection。)
GetHashCode 获取表示 ConfigurationElementCollection 实例的唯一值。 (继承自 ConfigurationElementCollection。)
GetTransformedAssemblyString 返回指定程序集名称的转换版本。 (继承自 ConfigurationElement。)
GetTransformedTypeString 返回指定类型名称的转换版本。 (继承自 ConfigurationElement。)
GetType 获取当前实例的 Type。 (继承自 Object。)
Init 将 ConfigurationElement 对象设置为其初始状态。 (继承自 ConfigurationElement。)
InitializeDefault 用于初始化 ConfigurationElement 对象的默认值集。 (继承自 ConfigurationElement。)
IsElementName 指示指定的 ConfigurationElement 是否存在于 ConfigurationElementCollection 中。 (继承自 ConfigurationElementCollection。)
IsElementRemovable 获取一个值,该值指示是否可从 ConfigurationElementCollection 中移除指定的 ConfigurationElement。 (继承自 ConfigurationElementCollection。)
IsModified 在派生的类中重写时,指示从最后一次保存或加载此 ConfigurationElementCollection 后是否对其进行了修改。 (继承自 ConfigurationElementCollection。)
IsReadOnly 获取一个值,该值指示 ConfigurationElementCollection 对象是否为只读。 (继承自 ConfigurationElementCollection。)
ListErrors 将此 ConfigurationElement 对象以及所有子元素中无效属性的错误添加到传递的列表中。 (继承自 ConfigurationElement。)
MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
OnDeserializeUnrecognizedAttribute 获取一个值,该值指示反序列化过程中是否遇到未知特性。 (继承自 ConfigurationElement。)
OnDeserializeUnrecognizedElement 导致配置系统引发异常。 (继承自 ConfigurationElementCollection。)
OnRequiredPropertyNotFound 未找到所需属性时引发异常。 (继承自 ConfigurationElement。)
PostDeserialize 反序列化后调用。 (继承自 ConfigurationElement。)
PreSerialize 序列化前调用。 (继承自 ConfigurationElement。)
Remove 移除集合中的一个元素。
Reset 在派生的类中重写时,将 ConfigurationElementCollection 重置为其未被修改时的状态。 (继承自 ConfigurationElementCollection。)
ResetModified 在派生的类中重写时,将 IsModified 属性的值重置为 false。 (继承自 ConfigurationElementCollection。)
SerializeElement 在派生的类中重写时,将配置数据写入配置文件中的 XML 元素。 (继承自 ConfigurationElementCollection。)
SerializeToXmlElement 当在派生类中实现后,将此配置元素的外部标记写入配置文件。 (继承自 ConfigurationElement。)
SetPropertyValue 将属性设置为指定值。 (继承自 ConfigurationElement。)
SetReadOnly 基础结构。为 ConfigurationElementCollection 对象和所有子元素设置 IsReadOnly 属性。 (继承自 ConfigurationElementCollection。)
ToString 返回表示当前对象的字符串。 (继承自 Object。)
Unmerge 基础结构。反转将配置层次结构的不同级别配置的信息合并在一起的效果 (继承自 ConfigurationElementCollection。)

提示和注释

ProviderSettingsCollection 类表示配置文件中的 providers 元素。

System.Configuration.ProviderSettingsCollection 类例子

下面的代码示例演示如何循环访问返回 ProviderSettingsCollection 的 Providers 属性。

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Configuration;
using System.Security.Permissions;

namespace Samples.AspNet
{

    // Shows how to use the ProviderSettings.
    public class UsingProviderSettings
    {

        [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
        private static void GetProviderSettings()
        {
            // Get the application configuration file.
            System.Configuration.Configuration config =
                    ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            ProtectedConfigurationSection pSection =
                config.GetSection("configProtectedData")
                as ProtectedConfigurationSection;

            ProviderSettingsCollection providerSettings =
              pSection.Providers;

            foreach (ProviderSettings pSettings in
                providerSettings)
            {


                Console.WriteLine(
                    "Provider settings name: {0}",
                    pSettings.Name);


                Console.WriteLine(
                    "Provider settings type: {0}",
                       pSettings.Type);

                NameValueCollection parameters =
                    pSettings.Parameters;

                IEnumerator pEnum =
                    parameters.GetEnumerator();

                int i = 0;
                while (pEnum.MoveNext())
                {
                    string pLength =
                        parameters[i].Length.ToString();
                    Console.WriteLine(
                        "Provider ssettings: {0} has {1} parameters",
                        pSettings.Name, pLength);

                }

            }

        }


        static void Main(string[] args)
        {

            GetProviderSettings();

        }
    }
}

继承层次结构

System.Object

System.Configuration.ConfigurationElement

System.Configuration.ConfigurationElementCollection

System.Configuration.ProviderSettingsCollection

命名空间

namespace: System.Configuration

程序集: System.Configuration(在 System.Configuration.dll 中)

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。