Enterprise Library 5 从我的 app.config 读取并完美验证。
有以下参考:
Microsoft.Practices.EnterpriseLibrary.Common v 5.0.414.0 Microsoft.Practices.EnterpriseLibrary.Validation v 5.0.414.0
和以下配置(在 app.config 中):
<configSections>
<section name="validation"
type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings,
Microsoft.Practices.EnterpriseLibrary.Validation" />
</configSections>
<validation>
<type name="WindowsFormsApplication1.AThing" assemblyName="WindowsFormsApplication1" defaultRuleset="default">
<ruleset name="default">
<properties>
<property name="Name">
<validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation"
negated="false" messageTemplate="Customer must have valid no"
tag="CustomerNo" name="Not Null Validator" />
</property>
</properties>
</ruleset>
</type>
</validation>
和以下代码:
public class AThing
{
public string Name { get; set; }
}
...
AThing bob = new AThing();
bob.Name = null;
ValidationResults vr = Validation.Validate(bob, "default");
Debug.Assert(!vr.IsValid);
...
vr.IsValid 正确地为假(因为“名称”为空,并且我有一个 NotNull 验证器)。
但是,当我替换对以下内容的引用时:
Microsoft.Practices.EnterpriseLibrary.Common v 6.0.0.0 Microsoft.Practices.EnterpriseLibrary.Validation v 6.0.0.0
并且什么都不改变,vs.IsValid 是真的......
经过多次谷歌搜索和堆栈溢出,我只找到了这个Enterprise Library 6 验证配置文件,(另一个有类似问题的用户......)(*this on CodePlex)