本文整理汇总了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();
}
示例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;
}
示例3: validateElement
private static void validateElement(object value, ValidationContext validationContext, List<ValidationResult> result)
{
DotNetAttributeValidation.TryValidate(value, result, validationContext.ValidateRecursively());
}
示例4: validateElement
private static void validateElement(object value, ValidationContext validationContext, List<ValidationResult> result)
{
FhirValidator.TryValidate(value, result, validationContext.ValidateRecursively());
}
示例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;
}
示例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;
}