Example #1
0
        public override IEnumerable <ValidationResult> Validate(System.Xml.Linq.XElement input)
        {
            if (null == input)
            {
                throw new ArgumentNullException("input");
            }
            string value = input.XPathEvaluate(this.XPathSelector, this.NamespaceManager).ToString();
            var    r     = new ValidationResult()
            {
                Exception          = new ContentValidation.ValidationException(this.ExceptionMessage, this.FailedValidationStatus),
                Message            = this.ExceptionMessage,
                ValidationGroup    = this.ValidationGroup,
                FurtherInformation = this.FurtherInformation
            };
            string details = String.Empty;

            if (false == this.PassesValidation(value, out details))
            {
                var vi = new ValidationInstance()
                {
                    Details = String.IsNullOrEmpty(details) ? String.Empty : details,
                    Status  = this.FailedValidationStatus
                };
                if (input is IXmlLineInfo)
                {
                    vi.LineNumber   = (input as IXmlLineInfo).LineNumber;
                    vi.LinePosition = (input as IXmlLineInfo).LinePosition;
                }
                r.Instances.Add(vi);
            }
            else
            {
                var vi = new ValidationInstance()
                {
                    Status = ValidationStatus.Passed
                };
                r.Instances.Add(vi);
            }
            return(new ValidationResult[] { r });
        }