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

            var count = 1;

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

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

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

            return(ValidationResult.Success);
        }
コード例 #2
0
        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");
            }

            try
            {
                // There is currently no validation in the portable .net
                // for the XDocument validation, would need to scan for
                // another implementation to cover this
#if !PORTABLE45
                var doc = XDocument.Parse(value as string);
                doc.Validate(SchemaCollection.ValidationSchemaSet, validationEventHandler: null);
#endif

                return(ValidationResult.Success);
            }
            catch (Exception e)
            {
                return(FhirValidator.BuildResult(validationContext, "Xml can not be parsed or is not valid: " + e.Message));
            }
        }
コード例 #3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

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

            var uri = (Uri)value;

            if (uri.IsAbsoluteUri)
            {
                var uris = uri.ToString();

                if (uris.StartsWith("urn:oid:") && !OidPatternAttribute.IsValid(uris))
                {
                    return(FhirValidator.BuildResult(validationContext, "Uri uses an urn:oid scheme, but the oid {0} is incorrect", uris));
                }
                else if (uris.StartsWith("urn:uuid:") && !UuidPatternAttribute.IsValid(uris))
                {
                    return(FhirValidator.BuildResult(validationContext, "Uri uses an urn:uuid schema, but the uuid {0} is incorrect", uris));
                }
            }

            return(ValidationResult.Success);
        }
コード例 #4
0
        private ValidationResult validateValue(object item, ValidationContext context)
        {
            if (item != null)
            {
#if PORTABLE45
                if (!Types.Any(type => type.GetTypeInfo().IsAssignableFrom(item.GetType().GetTypeInfo())))
#else
                if (!Types.Any(type => type.IsAssignableFrom(item.GetType())))
#endif
                { return(FhirValidator.BuildResult(context, "Value is of type {0}, which is not an allowed choice", item.GetType())); }
            }

            return(ValidationResult.Success);
        }
コード例 #5
0
        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 (Regex.IsMatch(value as string, "^" + Code.PATTERN + "$", RegexOptions.Singleline))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(FhirValidator.BuildResult(validationContext, "{0} is not a correctly formatted Code", value as string));
            }
        }
コード例 #6
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 (IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(FhirValidator.BuildResult(validationContext, "{0} is not a correctly formatted Oid", (string)value));
            }
        }
コード例 #7
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 (!IsValidValue(value as string))
            {
                return(FhirValidator.BuildResult(validationContext, "Uri uses an urn:oid or urn:uuid scheme, but the syntax {0} is incorrect", value as string));
            }
            else
            {
                return(ValidationResult.Success);
            }
        }
コード例 #8
0
        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 (IsValidValue(value as string))
            {
                return(ValidationResult.Success);
            }
            else
            {
                return(FhirValidator.BuildResult(validationContext, "Xml can not be parsed or is not valid according to the (limited) FHIR scheme"));
            }
        }