providersettingsvalidation.cs
来自「个人网站开发模板」· CS 代码 · 共 41 行
CS
41 行
using System;
using System.Configuration;
/// <summary>
// ensures the providerCollection contains a set of ProviderSettings, where each one
// "is a " Provider
/// </summary>
public class ProviderSettingsValidation : ConfigurationValidatorBase {
public override bool CanValidate(Type type)
{
return type == typeof(ProviderSettingsCollection);
}
/// <summary>
// validate the provider section
/// </summary>
public override void Validate(object value)
{
ProviderSettingsCollection providerCollection = value as ProviderSettingsCollection;
if (providerCollection != null)
{
foreach (ProviderSettings _provider in providerCollection)
{
if (String.IsNullOrEmpty(_provider.Type))
{
throw new ConfigurationErrorsException("Type was not defined in the provider");
}
Type dataAccessType = Type.GetType(_provider.Type);
if (dataAccessType == null)
{
throw (new InvalidOperationException("Provider's Type could not be found"));
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?