當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。