gpt4 book ai didi

c# - 此 ASP.NET MVC 验证代码是否易于阅读和遵循?

转载 作者:行者123 更新时间:2023-11-30 22:50:50 25 4
gpt4 key购买 nike

我想知道大家对此有何看法。代码是否易于理解?或者有更好的方法吗?顺便说一句,这就是我目前使用 ASP.NET MVC 进行验证的方式。我可以跟随它,但我是它的作者。出于某种原因,SO 正在删除验证器之间的换行符。

        public override Validation<MemberCreate> ValidationRules()
{
var validation = new Validation<MemberCreate>();

validation.Add(x => x.Name)
.LengthBetween(
Config.Member.NameMinLength,
Config.Member.NameMaxLength,
Resources.Errors.LengthBetweenNotValid.Fmt(
Resources.Titles.Name,
Config.Member.NameMinLength,
Config.Member.NameMaxLength))
.Characters(Resources.Errors.CharactersNotValid.Fmt(Resources.Titles.Name));

validation.Add(x => x.EmailAddress).Email(
Resources.Errors.EmailNotValid.Fmt(
Resources.Titles.EmailAddress));

validation.Add(x => x.VerifyEmailAddress).Equal(
x => x.EmailAddress,
Resources.Errors.CompareNotValid.Fmt(
Resources.Titles.VerifyEmailAddress,
Resources.Titles.EmailAddress));

validation.Add(x => x.PassWord).LengthGreaterThan(
Config.Member.PassWordMinLength,
Resources.Errors.LengthGreaterThanNotValid.Fmt(
Resources.Titles.PassWord,
Config.Member.PassWordMinLength));


validation.Add(x => x.VerifyPassWord).Equal(
x => x.PassWord,
Resources.Errors.CompareNotValid.Fmt(
Resources.Titles.VerifyPassWord,
Resources.Titles.PassWord));

return validation;
}

最佳答案

无论如何我都不是 C# 专家,但它看起来很简单。它似乎是将一堆规则放入某种结构中,我认为它随后将适用于验证某种消息。命令模式的应用,我想。

关于c# - 此 ASP.NET MVC 验证代码是否易于阅读和遵循?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/398801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com