コード例 #1
0
        public void Validate(ValidatorContext context)
        {
            var value = context.Value;

            if (value is null)
            {
                return;
            }

            if (!value.IsValid)
            {
                var id          = context.IsAttribute ? "Sch_AttributeValueDataTypeDetailed" : "Sch_ElementValueDataTypeDetailed";
                var description = context.IsAttribute ? ValidationResources.Sch_AttributeValueDataTypeDetailed : ValidationResources.Sch_ElementValueDataTypeDetailed;

                if (string.IsNullOrEmpty(value.InnerText))
                {
                    context.CreateError(
                        id: id,
                        description: SR.Format(description, context.QName, context.Value.InnerText, context.IsAttribute ? ValidationResources.Sch_EmptyAttributeValue : ValidationResources.Sch_EmptyElementValue),
                        errorType: ValidationErrorType.Schema);
                }
                else
                {
                    context.CreateError(
                        id: id,
                        description: SR.Format(description, context.QName, context.Value.InnerText, string.Empty),
                        errorType: ValidationErrorType.Schema);
                }
            }
        }
コード例 #2
0
        protected override void ValidateVersion(ValidatorContext context)
        {
            var value = GetValue(context);

            if (value != null && !value.IsValid)
            {
                var errorMessageResourceId = context.IsAttribute ? "Sch_AttributeValueDataTypeDetailed" : "Sch_ElementValueDataTypeDetailed";
                var message = context.IsAttribute ? ValidationResources.Sch_AttributeValueDataTypeDetailed : ValidationResources.Sch_ElementValueDataTypeDetailed;

                if (!value.IsEnum && string.IsNullOrEmpty(value.InnerText))
                {
                    context.CreateError(
                        id: errorMessageResourceId,
                        description: SR.Format(message, context.QName, context.Value.InnerText, ValidationResources.Sch_EmptyAttributeValue),
                        errorType: ValidationErrorType.Schema);
                }
                else
                {
                    context.CreateError(
                        id: errorMessageResourceId,
                        description: SR.Format(message, context.QName, value, ValidationResources.Sch_EnumerationConstraintFailed),
                        errorType: ValidationErrorType.Schema);
                }
            }
        }
コード例 #3
0
 protected override void ValidateVersion(ValidatorContext context)
 {
     if (IsRequired && context.Value is null)
     {
         context.CreateError(
             description: SR.Format(ValidationResources.Sch_MissRequiredAttribute, context.QName.Name),
             id: "Sch_MissRequiredAttribute",
             errorType: ValidationErrorType.Schema);
     }
 }
コード例 #4
0
        public void Validate(ValidatorContext context)
        {
            var errorRaised = false;
            var inner       = context.With(_ => errorRaised = true);

            foreach (var other in _others)
            {
                other.Validate(inner);

                if (!errorRaised)
                {
                    return;
                }

                errorRaised = false;
            }

            context.CreateError(
                id: "Sch_AttributeUnionFailedEx",
                description: SR.Format(ValidationResources.Sch_AttributeUnionFailedEx, context.QName, context.Value),
                errorType: ValidationErrorType.Schema);
        }