• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ValidationErrors类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ValidationErrors的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrors类的具体用法?C# ValidationErrors怎么用?C# ValidationErrors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ValidationErrors类属于命名空间,在下文中一共展示了ValidationErrors类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WhenInvalid

        public void WhenInvalid()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            IValidationErrors errors = new ValidationErrors();

            ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors");
            action.Parameters = new IExpression[] {Expression.Parse("Name"), Expression.Parse("Nationality")};
            
            action.Execute(false, context, null, errors);
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);
            Assert.AreEqual(context.Name + ", " + context.Nationality, errors.GetResolvedErrors("errors", new NullMessageSource())[0]);
        }
开发者ID:spring-projects,项目名称:spring-net,代码行数:13,代码来源:ErrorMessageActionTests.cs


示例2: FalseScalarExpression

        public void FalseScalarExpression()
        {
            Inventor tesla = new Inventor();
            tesla.Name = "Soltan Gris";

            ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null);
            validator.Actions = new ErrorMessageAction[] {new ErrorMessageAction("Wrong name", "InventorValidator") };
            IValidationErrors errors = new ValidationErrors();
            Assert.IsFalse(validator.Validate(tesla, errors));
            Assert.IsFalse(errors.IsEmpty);
            IList<string> namedErrors = errors.GetResolvedErrors("InventorValidator", new NullMessageSource());
            Assert.AreEqual(1, namedErrors.Count);
            string error = (string) namedErrors[0];
            Assert.AreEqual("Wrong name", error);
        }
开发者ID:Binodesk,项目名称:spring-net,代码行数:15,代码来源:ConditionValidatorTests.cs


示例3: WithNull

 public void WithNull()
 {
     RequiredValidator validator = new RequiredValidator();
     validator.Test = Expression.Parse("null");
     IValidationErrors errors = new ValidationErrors();
     Assert.IsFalse(validator.Validate(null, errors));
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:7,代码来源:RequiredValidatorTests.cs


示例4: Delete

 public bool Delete(ref ValidationErrors errors, string id)
 {
     try
     {
         //检查是否有下级
         if (dbContainer.SysModules.AsQueryable().Where(a => a.SysModule2.Id == id).Count() > 0)
         {
             errors.Add("有下属关联,请先删除下属!");
             return false;
         }
         m_Rep.Delete(dbContainer, id);
         if (dbContainer.SaveChanges() > 0)
         {
             //清理无用的项
             dbContainer.P_Sys_ClearUnusedRightOperate();
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:29,代码来源:SysModuleBLL.cs


示例5: Create

        /// <summary>
        /// 创建一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {
            int count = 1;

            foreach (string item in entity.SysOperationId.GetIdSort())
            {
                SysOperation sys = new SysOperation { Id = item };
                db.SysOperation.Attach(sys);
                entity.SysOperation.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                //创建后重置菜单编码
                List<int> flags = new List<int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
开发者ID:vipsms,项目名称:right,代码行数:34,代码来源:SysMenuBLL.cs


示例6: Create

 public bool Create(ref ValidationErrors errors, SysModuleOperateModel model)
 {
     try
     {
         SysModuleOperate entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysModuleOperate();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.KeyCode = model.KeyCode;
         entity.ModuleId = model.ModuleId;
         entity.IsValid = model.IsValid;
         entity.Sort = model.Sort;
         if (m_Rep.Create(entity) == 1)
         {
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:34,代码来源:SysModuleOperateBLL+.cs


示例7: OnField_WithValidationError

 public void OnField_WithValidationError()
 {
     ValidationErrors errors = new ValidationErrors();
     errors.AddError("country_name", new ValidationError("country_name", "91803", "invalid country"));
     Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.OnField("country_name")[0].Code);
     Assert.AreEqual("invalid country", errors.OnField("country_name")[0].Message);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:7,代码来源:ValidationErrorsTest.cs


示例8: Size_WithShallowErrors

 public void Size_WithShallowErrors()
 {
     ValidationErrors errors = new ValidationErrors();
     errors.AddError("country_name", new ValidationError("country_name", "1", "invalid country"));
     errors.AddError("another_field", new ValidationError("another_field", "2", "another message"));
     Assert.AreEqual(2, errors.Count);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:7,代码来源:ValidationErrorsTest.cs


示例9: Validate

 public override void Validate(string value, ValidationErrors errors)
 {
     if (!IsPresent(value))
     {
         errors.Add(Key,ErrorMessage);
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:7,代码来源:RequiredValidator.cs


示例10: WithNegativeNumber

 public void WithNegativeNumber()
 {
     RequiredValidator validator = new RequiredValidator();
     validator.Test = Expression.Parse("-100");
     IValidationErrors errors = new ValidationErrors();
     Assert.IsTrue(validator.Validate(null, errors));
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:7,代码来源:RequiredValidatorTests.cs


示例11: Create

        /// <summary>
        /// 创建一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {
            int count = 1;

            foreach (string item in entity.SysRoleId.GetIdSort())
            {
                SysRole sys = new SysRole { Id = item };
                db.SysRole.Attach(sys);
                entity.SysRole.Add(sys);
                count++;
            }

            foreach (string item in entity.SysDocumentId.GetIdSort())
            {
                SysDocument sys = new SysDocument { Id = item };
                db.SysDocument.Attach(sys);
                entity.SysDocument.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
开发者ID:vipsms,项目名称:right,代码行数:38,代码来源:SysPersonBLL.cs


示例12: Validate

 public void Validate(string password, string salt, string hashedPassword, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(password))//dont check salt and hashedPassword IsPresent
     {
         if (!new StringHasher().ComputedHashUsingGivenSaltMatchesGivenHash( password, salt, hashedPassword))
             errors.Add(Key, ErrorMessage);                
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:8,代码来源:HashedValueValidator.cs


示例13: StudyIntegrityValidationFailure

        public StudyIntegrityValidationFailure(ValidationErrors error, ValidationStudyInfo validationStudyInfo, string details)
            : base(details)
        {
            Platform.CheckForNullReference(validationStudyInfo, "validationStudyInfo");

            _error = error;
            _validationStudyInfo = validationStudyInfo;
        }
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:8,代码来源:StudyIntegrityValidationFailure.cs


示例14: Validate

 public override void Validate(string value, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(value))
     {
         if(value.Length > _maxLength || value.Length < _minLength)
             errors.Add(Key,ErrorMessage);
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:8,代码来源:StringLengthRangeValidator.cs


示例15: Validate

        public override void Validate(string guidstring, ValidationErrors errors)
        {
            Guid guid;

            if (!Guid.TryParse(guidstring, out guid))
            {
                errors.Add(Key, ErrorMessage);
            }
        }
开发者ID:aregsar,项目名称:rapido,代码行数:9,代码来源:GuidStringValidator.cs


示例16: OnField_WorksWithAllCommonCasing

 public void OnField_WorksWithAllCommonCasing()
 {
     ValidationError fieldError = new ValidationError("", "1", "");
     ValidationErrors errors = new ValidationErrors();
     errors.AddError("country_name", fieldError);
     Assert.AreEqual(fieldError, errors.OnField("country_name")[0]);
     Assert.AreEqual(fieldError, errors.OnField("country-name")[0]);
     Assert.AreEqual(fieldError, errors.OnField("countryName")[0]);
     Assert.AreEqual(fieldError, errors.OnField("CountryName")[0]);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:10,代码来源:ValidationErrorsTest.cs


示例17: Validate

        public override void Validate(string value, ValidationErrors errors)
        {
            if (RequiredValidator.IsPresent(value))
            {
                Regex regex = new Regex(_pattern);

                if (!regex.IsMatch(value.Trim()))
                    errors.Add(Key,ErrorMessage);
            }
        }
开发者ID:aregsar,项目名称:rapido,代码行数:10,代码来源:RegexValidator.cs


示例18: ForObject_WithNestedErrors

        public void ForObject_WithNestedErrors()
        {
            ValidationErrors addressErrors = new ValidationErrors();
            addressErrors.AddError("country_name", new ValidationError("country_name", "91803", "invalid country"));

            ValidationErrors errors = new ValidationErrors();
            errors.AddErrors("address", addressErrors);
            Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.ForObject("address").OnField("country_name")[0].Code);
            Assert.AreEqual("invalid country", errors.ForObject("address").OnField("country_name")[0].Message);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:10,代码来源:ValidationErrorsTest.cs


示例19: ForObject_WorksWithAllCommonCasing

 public void ForObject_WorksWithAllCommonCasing()
 {
     ValidationErrors nestedErrors = new ValidationErrors();
     ValidationErrors errors = new ValidationErrors();
     errors.AddErrors("credit-card", nestedErrors);
     Assert.AreEqual(nestedErrors, errors.ForObject("credit-card"));
     Assert.AreEqual(nestedErrors, errors.ForObject("credit_card"));
     Assert.AreEqual(nestedErrors, errors.ForObject("creditCard"));
     Assert.AreEqual(nestedErrors, errors.ForObject("CreditCard"));
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:10,代码来源:ValidationErrorsTest.cs


示例20: ShouldBuildAnElementFromErrors

        public void ShouldBuildAnElementFromErrors()
        {
            var error = new ValidationError("some error");
            var errors = new ValidationErrors<ParentInput>().Add(x => x.Child, error);
            var elementProvider = new Testable(typeof(NodeProvider<ParentInput>)).Create();

            var node = (NodeElement)elementProvider.With(errors).Build();

            Assert.That(node.Id, Is.Empty);
            var childElement = (LeafElement)node.Elements["Child"];
            Assert.That(childElement.Error, Is.EqualTo(error));
        }
开发者ID:jcono,项目名称:JC,代码行数:12,代码来源:ParentNodeProviderTests.cs



注:本文中的ValidationErrors类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ValidationEventHandler类代码示例发布时间:2022-05-24
下一篇:
C# ValidationErrorHandler类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap