当前位置: 首页>>代码示例>>C#>>正文


C# ValidationContext.ValidateRecursively方法代码示例

本文整理汇总了C#中System.ComponentModel.DataAnnotations.ValidationContext.ValidateRecursively方法的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext.ValidateRecursively方法的具体用法?C# ValidationContext.ValidateRecursively怎么用?C# ValidationContext.ValidateRecursively使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.DataAnnotations.ValidationContext的用法示例。


在下文中一共展示了ValidationContext.ValidateRecursively方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsValid

        // This attribute is a subclass of ValidationAttribute so that IsValid() is called on every 
        // FhirElement while validating. This allows us to extend validation into each FhirElement,
        // while normally, the .NET validation will only validate one level, but will not recurse
        // into each element. This is controllable by the SetValidateRecursively extension of the
        // ValidationContext
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if(validationContext == null) throw new ArgumentNullException("validationContext");

            if (value == null) return ValidationResult.Success;

            // If we should not validate 'value's elements, return immediately
            if (!validationContext.ValidateRecursively()) return ValidationResult.Success;

            IEnumerable list = value as IEnumerable;
            var result = new List<ValidationResult>();

            // If value is an enumerated type, validate all elements of the list
            if (list != null)
            {
                foreach (var element in list)
                {
                    if (element != null)
                    {
                        validateElement(element, validationContext, result);
                    }
                }
            }
            else
            {
                validateElement(value, validationContext, result);
            }

            return result.FirstOrDefault();                
        }
开发者ID:tiloc,项目名称:fhir-net-api,代码行数:35,代码来源:FhirElementAttribute.cs

示例2: Validate

        public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();

            if (Id != null && !Id.IsAbsoluteUri)
                result.Add(FhirValidator.BuildResult(validationContext, "Entry id must be an absolute URI"));

            if (Bundle.UriHasValue(SelfLink) && !SelfLink.IsAbsoluteUri)
                result.Add(FhirValidator.BuildResult(validationContext, "Entry selflink must be an absolute URI"));

            if (Links.FirstLink != null || Links.LastLink != null || Links.PreviousLink != null || Links.NextLink != null)
                result.Add(FhirValidator.BuildResult(validationContext, "Paging links can only be used on feeds, not entries"));

            if (Tags != null && validationContext.ValidateRecursively())
                FhirValidator.TryValidate(Tags,result,true);

            return result;
        }
开发者ID:jamesagnew,项目名称:fhir-net-api,代码行数:18,代码来源:BundleEntry.cs

示例3: validateElement

 private static void validateElement(object value, ValidationContext validationContext, List<ValidationResult> result)
 {
     DotNetAttributeValidation.TryValidate(value, result, validationContext.ValidateRecursively());
 }
开发者ID:rootdeveloper,项目名称:fhir-dstu1,代码行数:4,代码来源:FhirElementAttribute.cs

示例4: validateElement

 private static void validateElement(object value, ValidationContext validationContext, List<ValidationResult> result)
 {
     FhirValidator.TryValidate(value, result, validationContext.ValidateRecursively());
 }
开发者ID:jmandel,项目名称:fhir-with-ivy-dependencies,代码行数:4,代码来源:FhirElementAttribute.cs

示例5: Validate

        public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();

            // The ID field does not need to be an abolute URI,
            // this should be the ResourceIdentity.
            // if (Id != null && !new Uri(Id,UriKind.RelativeOrAbsolute).IsAbsoluteUri)
            //    result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry id must be an absolute URI"));

            if(Meta != null)
            {
                // if (!String.IsNullOrEmpty(this.Meta.VersionId) && !new Uri(Id,UriKind.RelativeOrAbsolute).IsAbsoluteUri)
                //     result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry selflink must be an absolute URI"));

                if (Meta.Tag != null && validationContext.ValidateRecursively())
                    DotNetAttributeValidation.TryValidate(Meta.Tag,result,true);
            }

            return result;
        }
开发者ID:alexandru360,项目名称:fhir-net-api,代码行数:20,代码来源:Resource.cs

示例6: Validate

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();

            //if (String.IsNullOrWhiteSpace(Title))
            //    result.Add(new ValidationResult("Feed must contain a title", FhirValidator.SingleMemberName("Title"));

            //if (!UriHasValue(Id))
            //    result.Add(new ValidationResult("Feed must have an id"));
            //else
            //    if (!Id.IsAbsoluteUri)
            //        result.Add(new ValidationResult("Feed id must be an absolute URI"));

            if (Id != null && !Id.IsAbsoluteUri)
                result.Add(FhirValidator.BuildResult(validationContext, "Feed id must be an absolute URI"));

            //if (LastUpdated == null)
            //    result.Add(new ValidationResult("Feed must have a updated date"));

            if (Links.SearchLink != null)
                result.Add(FhirValidator.BuildResult(validationContext, "Links with rel='search' can only be used on feed entries"));

            bool feedHasAuthor = !String.IsNullOrEmpty(this.AuthorName);

            if (Entries != null && validationContext.ValidateRecursively())
            {
                foreach (var entry in Entries.Where(e => e != null))
                {
                    if (!feedHasAuthor && entry is ResourceEntry && String.IsNullOrEmpty(((ResourceEntry)entry).AuthorName))
                        result.Add(FhirValidator.BuildResult(validationContext, "Bundle's author and Entry author cannot both be empty"));

                    FhirValidator.TryValidate(entry, result, validationContext.ValidateRecursively());
                }
            }

            return result;
        }
开发者ID:jamesagnew,项目名称:fhir-net-api,代码行数:37,代码来源:Bundle.cs


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