protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return((Min == 0) ? ValidationResult.Success :
                       DotNetAttributeValidation.BuildResult(validationContext, "Element with min. cardinality {0} cannot be null", Min));
            }

            var count = 1;

            if (value is IList && !ReflectionHelper.IsArray(value))
            {
                var list = value as IList;
                foreach (var elem in list)
                {
                    if (elem == null)
                    {
                        return(DotNetAttributeValidation.BuildResult(validationContext, "Repeating element cannot have empty/null values"));
                    }
                }
                count = list.Count;
            }

            if (count < Min)
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "Element has {0} elements, but min. cardinality is {1}", count, Min));
            }

            if (Max != -1 && count > Max)
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "Element has {0} elements, but max. cardinality is {1}", count, Max));
            }

            return(ValidationResult.Success);
        }
        private ValidationResult validateValue(object item, ValidationContext context)
        {
            if (item != null)
            {
                if (!Types.Any(type => type.GetTypeInfo().IsAssignableFrom(item.GetType().GetTypeInfo())))
                {
                    return(DotNetAttributeValidation.BuildResult(context, "Value is of type {0}, which is not an allowed choice", item.GetType()));
                }
            }

            return(ValidationResult.Success);
        }
Esempio n. 3
0
        private ValidationResult validateValue(object item, ValidationContext context)
        {
            if (item != null)
            {
                if (!IsAllowedType(item.GetType()))
                {
                    return(DotNetAttributeValidation.BuildResult(context, "Value is of type {0}, which is not an allowed choice", item.GetType()));
                }
            }

            return(ValidationResult.Success);
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            if (value.GetType() != typeof(string))
            {
                throw new ArgumentException("CodePatternAttribute can only be applied to string properties");
            }

            if (XHtml.IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "Xml can not be parsed or is not valid according to the (limited) FHIR scheme"));
            }
        }
Esempio n. 5
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            if (value.GetType() != typeof(string))
            {
                throw new ArgumentException("OidPatternAttribute can only be applied to string properties");
            }

            if (Oid.IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "{0} is not a correctly formatted Oid", (string)value));
            }
        }
Esempio n. 6
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            if (value.GetType() != typeof(string))
            {
                throw new ArgumentException("UriPatternAttribute can only be applied to .NET Uri properties");
            }

            if (!FhirUri.IsValidValue(value as string))
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "Uri uses an urn:oid or urn:uuid scheme, but the syntax {0} is incorrect", value as string));
            }
            else
            {
                return(ValidationResult.Success);
            }
        }
Esempio n. 7
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            if (value.GetType() != typeof(DateTimeOffset))
            {
                throw new ArgumentException("IdPatternAttribute can only be applied to DateTimeOffset properties");
            }

            if (Instant.IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(DotNetAttributeValidation.BuildResult(validationContext, "{0} is not a correctly formatted Instant", value as string));
            }
        }