Пример #1
0
        /// <summary>Gets an <see cref="AnnotatedModel"/> based on the <see cref="Type"/>.</summary>
        public AnnotatedModel GetAnnotededModel(Type type)
        {
            Guard.NotNull(type, nameof(type));

            lock (locker)
            {
                if (NotAnnotatedTypes.Contains(type))
                {
                    return(AnnotatedModel.None(type));
                }
                if (!Models.TryGetValue(type, out AnnotatedModel model))
                {
                    model = AnnotatedModel.Create(type);

                    // store the result.
                    if (model.IsValidatable)
                    {
                        Models[type] = model;
                    }
                    else
                    {
                        NotAnnotatedTypes.Add(type);
                    }
                }
                return(model);
            }
        }
Пример #2
0
 private Result <T> Validate <T>(Result <T> result, ValidationContext validationContext, AnnotatedModel annotations)
 {
     foreach (var property in annotations.Properties)
     {
         ValidateProperty(result, validationContext, property);
     }
     foreach (var attribute in annotations.TypeAttributes)
     {
         result.Add(attribute.GetValidationResult(result.Data, validationContext));
     }
     if (annotations.IsIValidatableObject)
     {
         result.AddRange(((IValidatableObject)result.Data).Validate(validationContext));
     }
     return(result);
 }