public void Validate(ValidationContext context) { var current = context.Stack.Current; var value = current.Value; if (value is null) { return; } if (!value.IsValid) { var id = current.IsAttribute ? "Sch_AttributeValueDataTypeDetailed" : "Sch_ElementValueDataTypeDetailed"; var description = current.IsAttribute ? ValidationResources.Sch_AttributeValueDataTypeDetailed : ValidationResources.Sch_ElementValueDataTypeDetailed; if (string.IsNullOrEmpty(value.InnerText)) { context.CreateError( id: id, description: SR.Format(description, current.Property.GetQName(), current.Value.InnerText, current.IsAttribute ? ValidationResources.Sch_EmptyAttributeValue : ValidationResources.Sch_EmptyElementValue), errorType: ValidationErrorType.Schema); } else { context.CreateError( id: id, description: SR.Format(description, current.Property.GetQName(), current.Value.InnerText, string.Empty), errorType: ValidationErrorType.Schema); } } }
protected override void ValidateVersion(ValidationContext context) { var current = context.Current; var value = GetValue(current); if (value != null && !value.IsValid) { var errorMessageResourceId = current.IsAttribute ? "Sch_AttributeValueDataTypeDetailed" : "Sch_ElementValueDataTypeDetailed"; var message = current.IsAttribute ? ValidationResources.Sch_AttributeValueDataTypeDetailed : ValidationResources.Sch_ElementValueDataTypeDetailed; if (!value.IsEnum && string.IsNullOrEmpty(value.InnerText)) { context.CreateError( id: errorMessageResourceId, description: SR.Format(message, current.Property.GetQName(), current.Value.InnerText, ValidationResources.Sch_EmptyAttributeValue), errorType: ValidationErrorType.Schema); } else { context.CreateError( id: errorMessageResourceId, description: SR.Format(message, current.Property.GetQName(), value, ValidationResources.Sch_EnumerationConstraintFailed), errorType: ValidationErrorType.Schema); } } }
public void Validate(ValidationContext context) { var errorRaised = false; using (context.Stack.Push(_ => errorRaised = true)) { foreach (var other in _others) { other.Validate(context); if (!errorRaised) { return; } errorRaised = false; } } var current = context.Stack.Current; context.CreateError( id: "Sch_AttributeUnionFailedEx", description: SR.Format(ValidationResources.Sch_AttributeUnionFailedEx, current.Property.QName, current.Value), errorType: ValidationErrorType.Schema); }
void IValidator.Validate(ValidationContext context) { if (DataType is null || !DataType.HasValue) { return; } if (CellValue is CellValue value) { var success = DataType.Value switch { CellValues.Boolean => value.TryGetBoolean(out _), CellValues.Date => value.TryGetDateTimeOffset(out _) || value.TryGetDateTime(out _), CellValues.Number => value.TryGetInt(out _) || value.TryGetDouble(out _) || value.TryGetDecimal(out _), _ => true, }; if (!success) { context.CreateError( id: "Sem_CellValue", errorType: ValidationErrorType.Semantic, description: string.Format(ValidationResources.Sem_CellValue, value.InnerText, DataType.Value)); } } }
public void Validate(ValidationContext context) { var current = context.Stack.Current; if (!context.FileFormat.AtLeast(OfficeVersion) && current.Value?.HasValue == true && !context.McContext.IsIgnorableNs(current.Property.GetQName().Namespace)) { context.CreateError( id: "Sch_UndeclaredAttribute", description: SR.Format(ValidationResources.Sch_UndeclaredAttribute, current.Property.GetQName()), errorType: ValidationErrorType.Schema); } }
protected override void ValidateVersion(ValidationContext context) { var current = context.Stack.Current; if (IsRequired && current.Value is null) { context.CreateError( description: SR.Format(ValidationResources.Sch_MissRequiredAttribute, current.Property.GetQName().Name), id: "Sch_MissRequiredAttribute", errorType: ValidationErrorType.Schema); } }