public static bool IsValidValue(string value) { Uri uri = null; try { uri = new Uri((string)value, UriKind.RelativeOrAbsolute); } catch { return(false); } if (uri.IsAbsoluteUri) { var uris = uri.ToString(); if (uris.StartsWith("urn:oid:") && !OidPatternAttribute.IsValidValue(uris)) { return(false); } else if (uris.StartsWith("urn:uuid:") && !UuidPatternAttribute.IsValidValue(uris)) { return(false); } } return(true); }
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); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value == null) { return(ValidationResult.Success); } if (value.GetType() != typeof(string)) { throw new ArgumentException("UuidPatternAttribute can only be applied to string properties"); } if (UuidPatternAttribute.IsValid((string)value)) { return(ValidationResult.Success); } else { return(FhirValidator.BuildResult(validationContext, "{0} is not a correctly formatted Uuid", (string)value)); } }