本文整理汇总了C#中Member.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# Member.Validate方法的具体用法?C# Member.Validate怎么用?C# Member.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Member
的用法示例。
在下文中一共展示了Member.Validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: The_attributes_on_the_properties_should_be_used_for_validation
public void The_attributes_on_the_properties_should_be_used_for_validation()
{
IValidator<Member> validator = new EntityValidator<Member>();
Member member = new Member();
IEnumerable<IViolation> violations;
member.Validate(validator, out violations);
Assert.That(validator.IsValid(member, out violations), Is.False);
List<IViolation> violationList = new List<IViolation>(violations);
Assert.That(violationList.Count, Is.EqualTo(2));
Assert.That(violationList[0], Is.TypeOf(typeof(NullValueViolation)));
Assert.That(violationList[1], Is.TypeOf(typeof(NullValueViolation)));
}
示例2: SetRegisterFields
private void SetRegisterFields(TemplateEngine te)
{
te.Put(TagFields.PageTitle, "注册");
if (Request.IsPost())
{
var member = new Member();
member.RealName = Request.Get<string>("realName");
member.Mobile = Request.Get<string>("userMobile");
member.Password = Request.Get<string>("password").ToMd5();
member.RegisterIP = Request.GetIPAddress();
var errors = member.Validate();
var password = Request.Get<string>("password");
var password1 = Request.Get<string>("password1");
if (string.IsNullOrEmpty(password))
errors.Add("设置密码不能为空!");
if (string.IsNullOrEmpty(password1))
errors.Add("确认密码不能为空!");
if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(password1) && password != password1)
errors.Add("两次密码不一致!");
if (errors.Count > 0)
{
te.Put(TagFields.Errors, GetErrorsHtml(errors));
}
else
{
member.Save();
}
}
}