示例#1
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew"></param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            if (Name.IsNullOrEmpty())
            {
                throw new ArgumentNullException(__.Name, _.Name.DisplayName + "不能为空!");
            }
            if (Password.IsNullOrEmpty())
            {
                throw new ArgumentNullException(__.Password, _.Password.DisplayName + "不能为空!");
            }
            //if (Password.Length != 16 && Password.Length != 32) throw new ArgumentOutOfRangeException(__.Password, _.Password.DisplayName + "非法!");
            //if (Name.Length < 8) throw new ArgumentOutOfRangeException(__.Name, _.Name.DisplayName + "最短8个字符!" + Name);
            //if (Name.Length > 16) throw new ArgumentOutOfRangeException(__.Name, _.Name.DisplayName + "最长16个字符!" + Name);

            // 修正显示名
            if (!NickName.IsNullOrEmpty() && NickName.Length > 16)
            {
                NickName = NickName.Substring(0, 16);
            }

            // 建议先调用基类方法,基类方法会对唯一索引的数据进行验证
            base.Valid(isNew);
        }