SettingsProvider 类


在应用程序设置结构中作为派生自定义设置提供程序的基类。Acts as a base class for deriving custom settings providers in the application settings architecture.

public ref class SettingsProvider abstract : System::Configuration::Provider::ProviderBase
public abstract class SettingsProvider : System.Configuration.Provider.ProviderBase
type SettingsProvider = class
    inherit ProviderBase
Public MustInherit Class SettingsProvider
Inherits ProviderBase


设置提供程序定义用于存储应用程序设置体系结构中使用的配置数据的机制。A settings provider defines the mechanism for storing configuration data used in the application settings architecture. .NET Framework 包含单个默认设置提供程序(LocalFileSettingsProvider),该提供程序将配置数据存储到本地文件系统。The .NET Framework contains a single default settings provider, LocalFileSettingsProvider, which stores configuration data to the local file system. 不过,您可以通过从抽象 SettingsProvider 类派生来创建备用存储机制。However, you can create alternate storage mechanisms by deriving from the abstract SettingsProvider class. 包装类使用的提供程序通过使用 SettingsProviderAttribute修饰包装类来确定。The provider that a wrapper class uses is determined by decorating the wrapper class with the SettingsProviderAttribute. 如果未提供此属性,则使用默认的 LocalFileSettingsProviderIf this attribute is not provided, the default, LocalFileSettingsProvider, is used.

在创建自定义设置提供程序时,必须至少为此类的三个方法提供实现: GetPropertyValuesSetPropertyValuesApplicationNameWhen you create a custom settings provider, at minimum, you must provide implementations for the three methods of this class: GetPropertyValues, SetPropertyValues and ApplicationName.

对于客户端应用程序,还可以通过实现 IApplicationSettingsProvider 接口,将更多标准化功能添加到自定义提供程序。For client applications, you can add more standardized functionality to a custom provider by also implementing the IApplicationSettingsProvider interface. 此接口对在 ApplicationSettingsBase 类中找到的方法进行镜像,此类主要启用版本控制支持。This interface mirrors methods found in the ApplicationSettingsBase class, which mainly enables versioning support.

通常,应将设置提供程序设计为单实例,以避免存储资源争用。Typically, you should design settings providers to be single-instanced to avoid storage resource contention. 提供程序也应该是线程安全的,因为它们可以从单个应用程序域中的多个包装实例或不同域中的多个应用程序同时调用。Providers should also be thread-safe because they can be called simultaneously from multiple wrapper instances in a single application domain or from multiple applications in different domains.

设置提供程序必须至少识别三个属性-ApplicationScopedSettingAttributeUserScopedSettingAttributeDefaultSettingValueAttributeAt minimum, a settings provider must recognize three attributes - ApplicationScopedSettingAttribute, UserScopedSettingAttribute, and DefaultSettingValueAttribute. 有关可应用于应用程序设置的属性的完整列表,请参阅应用程序设置属性For a full listing of attributes that can be applied to application settings, see Application Settings Attributes. 自定义设置提供程序应按以下方式解析应用于设置属性的特性:A custom setting provider should resolve attributes applied to settings properties in the following manner:

  1. 如果提供程序可满足特性隐含的请求,显然应该这样做。If the provider can fulfill the request implied by the attribute, obviously it should do so.

  2. 如果提供程序无法满足请求,则应以无提示方式将其忽略。If the provider cannot fulfill the request, it should ignore it silently.

  3. 如果两个或多个属性冲突,则为;例如,使用 ApplicationScopedSettingAttributeUserScopedSettingAttribute修饰的属性;提供程序应引发 ConfigurationExceptionIf two or more properties conflict; for example, a property being decorated with both ApplicationScopedSettingAttribute and UserScopedSettingAttribute; the provider should throw a ConfigurationException.



初始化 SettingsProvider 类的实例。Initializes an instance of the SettingsProvider class.



获取或设置当前运行的应用程序的名称。Gets or sets the name of the currently running application.


获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(继承自 ProviderBase)

获得一个友好名称,用于在配置过程中引用提供程序。Gets the friendly name used to refer to the provider during configuration.

(继承自 ProviderBase)



确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetPropertyValues(SettingsContext, SettingsPropertyCollection)

返回指定应用程序实例的设置属性值集合和设置属性组。Returns the collection of settings property values for the specified application instance and settings property group.


获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Initialize(String, NameValueCollection)

初始化配置生成器。Initializes the configuration builder.

(继承自 ProviderBase)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetPropertyValues(SettingsContext, SettingsPropertyValueCollection)

设置指定的属性设置组的值。Sets the values of the specified group of property settings.


返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)