CustomValidation 怎样根据一个属性验证另一个属性

runerback 2015-12-15 01:40:32
想要根据一个int型的FileType来验证string型的FileName

Metadata类:

public int FileType { get; set; }
[CustomValidation(typeof(ValidationUtils), "CheckFileName")]
public string FileName { get; set; }


验证类 ValidationUtils(中的验证方法):

public static ValidationResult CheckFileName(string fileName)
{
// ???
/*
if(fileType == 1)
{

}
else if(fileType == 2)
{

}
else
{

}
*/
return ValidationResult.Success;
}

是不是这种模式不适合做多字段同时验证?
...全文
283 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
秋的红果实 2015-12-18
  • 打赏
  • 举报
回复
没看懂你在说什么
runerback 2015-12-18
  • 打赏
  • 举报
回复
没人。。求结帖

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧