-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial validation attribute support (#590)
This change removes the need for some of the data files by moving the validation info to be expressed as attributes on properties/classes.
- Loading branch information
1 parent
d5d41e4
commit 98df2f9
Showing
116 changed files
with
14,376 additions
and
34,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/DocumentFormat.OpenXml/Framework/Validation/EnumValidatorAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using DocumentFormat.OpenXml.Validation; | ||
using System; | ||
|
||
namespace DocumentFormat.OpenXml.Framework | ||
{ | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | ||
internal sealed class EnumValidatorAttribute : VersionedValidatorAttribute | ||
{ | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/DocumentFormat.OpenXml/Framework/Validation/INameProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Xml; | ||
|
||
namespace DocumentFormat.OpenXml.Framework | ||
{ | ||
internal interface INameProvider | ||
{ | ||
XmlQualifiedName QName { get; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/DocumentFormat.OpenXml/Framework/Validation/IOpenXmlSimpleTypeValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace DocumentFormat.OpenXml.Framework | ||
{ | ||
internal interface IOpenXmlSimpleTypeValidator | ||
{ | ||
void Validate(ValidatorContext context); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/DocumentFormat.OpenXml/Framework/Validation/IUnionValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace DocumentFormat.OpenXml.Framework | ||
{ | ||
internal interface IUnionValidator : IOpenXmlSimpleTypeValidator | ||
{ | ||
byte? UnionId { get; } | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/DocumentFormat.OpenXml/Framework/Validation/ListValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using DocumentFormat.OpenXml.Validation; | ||
|
||
namespace DocumentFormat.OpenXml.Framework | ||
{ | ||
internal class ListValidator : IOpenXmlSimpleTypeValidator | ||
{ | ||
public static IOpenXmlSimpleTypeValidator Instance { get; } = new ListValidator(); | ||
|
||
private ListValidator() | ||
{ | ||
} | ||
|
||
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.