Skip to content

Commit b69575f

Browse files
committed
Modernize codebase style and remove legacy artifacts
- Switch to auto-properties - Delete obsolete hand-maintained XML doc files (NMatrix.Schematron.xml, Schematron.xml) - Replace CollectionBase subclasses with List<T> aliases - Rename private fields from _camelCase to camelCase - Convert methods/properties to expression-bodied members - Remove #region blocks and legacy XML doc tags
1 parent c941252 commit b69575f

43 files changed

Lines changed: 715 additions & 5321 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,5 @@ dotnet test Schematron.slnx
4747

4848
## Conventions
4949

50-
- **Target framework**: `net48` for all projects (WebServices requires .NET Framework due to `System.Web.Services`).
51-
- **Versioning**: Managed by the [GitInfo](https://github.com/devlooped/GitInfo) package; base version comes from the `VERSION` file at the repo root.
52-
- **NuGet metadata**: Defined in `src/Directory.Build.props` and per-project `<PropertyGroup>`.
5350
- **C# language version**: `latest` — use modern idioms (expression-bodied members, `var`, `string.IsNullOrEmpty`, `throw;`, pattern matching).
5451
- **No custom build scripts**: Use standard `dotnet` CLI; no `build.cmd` / `build.proj`.

src/Schematron.Tests/ReferenceSchematronRunner.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ static class ReferenceSchematronRunner
1616
const string XsltDir = "./Content/xslt";
1717
const string SvrlNs = "http://purl.oclc.org/dsdl/svrl";
1818

19-
static readonly XslCompiledTransform _include = LoadXslt(Path.Combine(XsltDir, "iso_dsdl_include.xsl"));
20-
static readonly XslCompiledTransform _abstract = LoadXslt(Path.Combine(XsltDir, "iso_abstract_expand.xsl"));
21-
static readonly XslCompiledTransform _svrl = LoadXslt(Path.Combine(XsltDir, "iso_svrl_for_xslt1.xsl"));
19+
static readonly XslCompiledTransform include = LoadXslt(Path.Combine(XsltDir, "iso_dsdl_include.xsl"));
20+
static readonly XslCompiledTransform abstractExpand = LoadXslt(Path.Combine(XsltDir, "iso_abstract_expand.xsl"));
21+
static readonly XslCompiledTransform svrl = LoadXslt(Path.Combine(XsltDir, "iso_svrl_for_xslt1.xsl"));
2222

2323
static XslCompiledTransform LoadXslt(string path)
2424
{
@@ -36,14 +36,14 @@ static XslCompiledTransform LoadXslt(string path)
3636
public static SvrlResult Validate(string schemaPath, string xmlContent, string? phase = null)
3737
{
3838
// Step 1: resolve includes
39-
string included = ApplyTransform(_include, ReadFile(schemaPath), baseUri: Path.GetFullPath(schemaPath));
39+
string included = ApplyTransform(include, ReadFile(schemaPath), baseUri: Path.GetFullPath(schemaPath));
4040
// Step 2: expand abstract patterns
41-
string expanded = ApplyTransform(_abstract, included);
41+
string expanded = ApplyTransform(abstractExpand, included);
4242
// Step 3: generate validator XSLT from schema
4343
var svrlArgs = new XsltArgumentList();
4444
if (!string.IsNullOrEmpty(phase))
4545
svrlArgs.AddParam("phase", "", phase);
46-
string validatorXslt = ApplyTransform(_svrl, expanded, args: svrlArgs);
46+
string validatorXslt = ApplyTransform(ReferenceSchematronRunner.svrl, expanded, args: svrlArgs);
4747
// Step 4: apply validator XSLT to the XML instance
4848
var validator = new XslCompiledTransform();
4949
using (var validatorReader = XmlReader.Create(new StringReader(validatorXslt)))

src/Schematron.Tests/ValidatorTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.IO;
21
using System.Xml;
32
using System.Xml.Schema;
43
using System.Xml.Serialization;
@@ -78,7 +77,7 @@ public void ValidateShouldReturnSchematronValidationResultWhenSchematronConstrai
7877
using (var stream = new MemoryStream(System.Text.Encoding.Unicode.GetBytes(ex.Message)))
7978
using (var reader = XmlReader.Create(stream))
8079
{
81-
var obj = (Schematron.Serialization.SchematronValidationResultTempObjectModel.Output)serializer.Deserialize(reader);
80+
var obj = (Schematron.Serialization.SchematronValidationResultTempObjectModel.Output?)serializer.Deserialize(reader);
8281

8382
// Assert
8483

@@ -282,7 +281,7 @@ public void SchematronValidationResultIncludesExpandedValueElements()
282281

283282
using (var doc = XmlReader.Create(XmlContentLocation))
284283
{
285-
var result = (IXPathNavigable)null;
284+
IXPathNavigable? result = default;
286285

287286
try
288287
{
@@ -292,7 +291,7 @@ public void SchematronValidationResultIncludesExpandedValueElements()
292291
{
293292
System.Diagnostics.Debug.WriteLine(ex.Message);
294293
string expectedMessage = "<text>Attributes sex (Female) and title (Mr) must have compatible values on element customer.</text>";
295-
Xunit.Assert.True(ex.Message.Contains(expectedMessage));
294+
Xunit.Assert.Contains(expectedMessage, ex.Message);
296295
}
297296
Xunit.Assert.Null(result);
298297
}

src/Schematron/Assert.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public class Assert : Test
2121
/// <summary>Constructs a new Assert object.</summary>
2222
/// <param name="test">XPath expression to test.</param>
2323
/// <param name="message">Message to display if the assert fails.</param>
24-
internal protected Assert(string test, string message) : base(test, message)
25-
{
26-
}
24+
internal protected Assert(string test, string message) : base(test, message) { }
2725
}
2826

src/Schematron/BadSchemaException.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,26 @@ public class BadSchemaException : ApplicationException
1313
/// <summary>
1414
/// Initializes a new instance of the <see cref="BadSchemaException"/> class.
1515
/// </summary>
16-
public BadSchemaException()
17-
{
18-
}
16+
public BadSchemaException() { }
1917

2018
/// <summary>
2119
/// Initializes a new instance of the <see cref="BadSchemaException"/> class.
2220
/// </summary>
2321
/// <param name="message">The error message that explains the reason for the exception.</param>
24-
public BadSchemaException(string message) : base(message)
25-
{
26-
}
22+
public BadSchemaException(string message) : base(message) { }
2723

2824
/// <summary>
2925
/// Initializes a new instance of the <see cref="BadSchemaException"/> class.
3026
/// </summary>
3127
/// <param name="info">Info</param>
3228
/// <param name="context">Context</param>
33-
protected BadSchemaException(SerializationInfo info, StreamingContext context) :
34-
base(info, context)
35-
{
36-
}
29+
protected BadSchemaException(SerializationInfo info, StreamingContext context) : base(info, context) { }
3730

3831
/// <summary>
3932
/// Initializes a new instance of the <see cref="BadSchemaException"/> class.
4033
/// </summary>
4134
/// <param name="message">The error message that explains the reason for the exception.</param>
4235
/// <param name="innerException">The exception that is the cause of the current exception.</param>
43-
public BadSchemaException(string message, Exception innerException) :
44-
base(message, innerException)
45-
{
46-
}
36+
public BadSchemaException(string message, Exception innerException) : base(message, innerException) { }
4737
}
4838

src/Schematron/CompiledExpressions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Xml;
21
using System.Xml.XPath;
32

43
namespace Schematron;
@@ -32,7 +31,7 @@ class CompiledExpressions
3231

3332
static CompiledExpressions()
3433
{
35-
XmlNamespaceManager mgr = Config.DefaultNsManager;
34+
var mgr = Config.DefaultNsManager;
3635

3736
Schema = Config.DefaultNavigator.Compile("//sch:schema");
3837
Schema.SetContext(mgr);
@@ -75,8 +74,6 @@ static CompiledExpressions()
7574
// Diagnostics.SetContext(mgr);
7675
}
7776

78-
CompiledExpressions()
79-
{
80-
}
77+
CompiledExpressions() { }
8178
}
8279

src/Schematron/Config.cs

Lines changed: 68 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -11,87 +11,83 @@ namespace Schematron;
1111
/// This class is public to allow inheritors of Schematron elements
1212
/// to use these global settings.
1313
/// </remarks>
14-
/// <author ref="kzu" />
15-
/// <progress amount="100" />
1614
public class Config
1715
{
16+
static readonly IFormatter formatter;
17+
static readonly XPathNavigator navigator;
18+
static readonly XmlNamespaceManager nsmanager;
19+
static readonly Schema full;
20+
static readonly Schema embedded;
21+
static readonly string uid = string.Intern(Guid.NewGuid().ToString());
22+
1823
/// <summary>
1924
/// Initializes global settings.
2025
/// </summary>
2126
static Config()
2227
{
2328
// Default formatter outputs in text format a log with results.
24-
_formatter = new LogFormatter();
29+
formatter = new LogFormatter();
2530

2631
//TODO: create and load the schematron full and embedded versions for validation.
27-
_embedded = new Schema();
28-
_embedded.Phases.Add(_embedded.CreatePhase(Phase.All));
29-
_full = new Schema();
30-
_full.Phases.Add(_full.CreatePhase(Phase.All));
32+
embedded = new Schema();
33+
embedded.Phases.Add(embedded.CreatePhase(Phase.All));
34+
full = new Schema();
35+
full.Phases.Add(full.CreatePhase(Phase.All));
3136

3237
//TODO: should we move all the schema language elements to a resource file?
33-
_navigator = new XmlDocument().CreateNavigator();
34-
_navigator.NameTable.Add("active");
35-
_navigator.NameTable.Add("pattern");
36-
_navigator.NameTable.Add("assert");
37-
_navigator.NameTable.Add("test");
38-
_navigator.NameTable.Add("role");
39-
_navigator.NameTable.Add("id");
40-
_navigator.NameTable.Add("diagnostics");
41-
_navigator.NameTable.Add("icon");
42-
_navigator.NameTable.Add("subject");
43-
_navigator.NameTable.Add("diagnostic");
44-
_navigator.NameTable.Add("dir");
45-
_navigator.NameTable.Add("emph");
46-
_navigator.NameTable.Add("extends");
47-
_navigator.NameTable.Add("rule");
48-
_navigator.NameTable.Add("key");
49-
_navigator.NameTable.Add("name");
50-
_navigator.NameTable.Add("path");
51-
_navigator.NameTable.Add("ns");
52-
_navigator.NameTable.Add("uri");
53-
_navigator.NameTable.Add("prefix");
54-
_navigator.NameTable.Add("p");
55-
_navigator.NameTable.Add("class");
56-
_navigator.NameTable.Add("see");
57-
_navigator.NameTable.Add("phase");
58-
_navigator.NameTable.Add("fpi");
59-
_navigator.NameTable.Add("report");
60-
_navigator.NameTable.Add("context");
61-
_navigator.NameTable.Add("abstract");
62-
_navigator.NameTable.Add("schema");
63-
_navigator.NameTable.Add("schemaVersion");
64-
_navigator.NameTable.Add("defaultPhase");
65-
_navigator.NameTable.Add("version");
66-
_navigator.NameTable.Add("span");
67-
_navigator.NameTable.Add("title");
68-
_navigator.NameTable.Add("value-of");
69-
_navigator.NameTable.Add("select");
70-
_navigator.NameTable.Add(Schema.IsoNamespace);
71-
_navigator.NameTable.Add(Schema.LegacyNamespace);
38+
navigator = new XmlDocument().CreateNavigator();
39+
navigator.NameTable.Add("active");
40+
navigator.NameTable.Add("pattern");
41+
navigator.NameTable.Add("assert");
42+
navigator.NameTable.Add("test");
43+
navigator.NameTable.Add("role");
44+
navigator.NameTable.Add("id");
45+
navigator.NameTable.Add("diagnostics");
46+
navigator.NameTable.Add("icon");
47+
navigator.NameTable.Add("subject");
48+
navigator.NameTable.Add("diagnostic");
49+
navigator.NameTable.Add("dir");
50+
navigator.NameTable.Add("emph");
51+
navigator.NameTable.Add("extends");
52+
navigator.NameTable.Add("rule");
53+
navigator.NameTable.Add("key");
54+
navigator.NameTable.Add("name");
55+
navigator.NameTable.Add("path");
56+
navigator.NameTable.Add("ns");
57+
navigator.NameTable.Add("uri");
58+
navigator.NameTable.Add("prefix");
59+
navigator.NameTable.Add("p");
60+
navigator.NameTable.Add("class");
61+
navigator.NameTable.Add("see");
62+
navigator.NameTable.Add("phase");
63+
navigator.NameTable.Add("fpi");
64+
navigator.NameTable.Add("report");
65+
navigator.NameTable.Add("context");
66+
navigator.NameTable.Add("abstract");
67+
navigator.NameTable.Add("schema");
68+
navigator.NameTable.Add("schemaVersion");
69+
navigator.NameTable.Add("defaultPhase");
70+
navigator.NameTable.Add("version");
71+
navigator.NameTable.Add("span");
72+
navigator.NameTable.Add("title");
73+
navigator.NameTable.Add("value-of");
74+
navigator.NameTable.Add("select");
75+
navigator.NameTable.Add(Schema.IsoNamespace);
76+
navigator.NameTable.Add(Schema.LegacyNamespace);
7277

7378
//Namespace manager initialization
74-
_nsmanager = new XmlNamespaceManager(_navigator.NameTable);
75-
_nsmanager.AddNamespace(String.Empty, Schema.Namespace);
76-
_nsmanager.AddNamespace("sch", Schema.Namespace);
77-
_nsmanager.AddNamespace("xsd", System.Xml.Schema.XmlSchema.Namespace);
78-
}
79-
80-
Config()
81-
{
79+
nsmanager = new XmlNamespaceManager(navigator.NameTable);
80+
nsmanager.AddNamespace(string.Empty, Schema.Namespace);
81+
nsmanager.AddNamespace("sch", Schema.Namespace);
82+
nsmanager.AddNamespace("xsd", System.Xml.Schema.XmlSchema.Namespace);
8283
}
8384

84-
static IFormatter _formatter;
85+
Config() { }
8586

8687
/// <summary>
8788
/// The default object to use to format messages from validation.
8889
/// </summary>
89-
public static IFormatter DefaultFormatter
90-
{
91-
get { return _formatter; }
92-
}
93-
94-
static XPathNavigator _navigator;
90+
public static IFormatter DefaultFormatter => formatter;
9591

9692
/// <summary>
9793
/// A default empty navigator used to pre-compile XPath expressions.
@@ -110,56 +106,35 @@ public static IFormatter DefaultFormatter
110106
/// <seealso cref="CompiledExpressions"/>
111107
/// </para>
112108
/// </example>
113-
internal static XPathNavigator DefaultNavigator
114-
{
115-
// Returning a cloned navigator appeared to solve the threading issues
116-
// we had, because a single navigator was being used to compile all the
117-
// expressions in all potential threads.
118-
get { return _navigator.Clone(); }
119-
}
120-
121-
static XmlNamespaceManager _nsmanager;
109+
/// <devdoc>
110+
/// Returning a cloned navigator appeared to solve the threading issues
111+
/// we had, because a single navigator was being used to compile all the
112+
/// expressions in all potential threads.
113+
/// </devdoc>
114+
internal static XPathNavigator DefaultNavigator => navigator.Clone();
122115

123116
/// <summary>
124117
/// Manager to use when executing expressions that validate or
125118
/// load Schematron and Embedded Schematron schemas.
126119
/// </summary>
127-
public static XmlNamespaceManager DefaultNsManager
128-
{
129-
get { return _nsmanager; }
130-
}
131-
132-
static Schema _full;
120+
public static XmlNamespaceManager DefaultNsManager => nsmanager;
133121

134122
/// <summary>
135123
/// A cached schema in Schematron format to validate schematron schemas.
136124
/// </summary>
137125
/// <remarks>This is the version for standalone schemas.</remarks>
138-
public static Schema FullSchematron
139-
{
140-
get { return _full; }
141-
}
142-
143-
static Schema _embedded;
126+
public static Schema FullSchematron => full;
144127

145128
/// <summary>
146129
/// A cached schema in Schematron format to validate schematron schemas.
147130
/// </summary>
148131
/// <remarks>This is the version for embedded schemas.</remarks>
149-
public static Schema EmbeddedSchematron
150-
{
151-
get { return _embedded; }
152-
}
153-
154-
static string _uid = String.Intern(Guid.NewGuid().ToString());
132+
public static Schema EmbeddedSchematron => embedded;
155133

156134
/// <summary>
157135
/// A unique identifier to use for internal keys.
158136
/// </summary>
159-
public static string UniqueKey
160-
{
161-
get { return _uid; }
162-
}
137+
public static string UniqueKey => uid;
163138

164139
/// <summary>
165140
/// Force all static constructors in the library.
@@ -171,5 +146,4 @@ public static void Setup()
171146
System.Diagnostics.Trace.Write(TagExpressions.Dir.RightToLeft);
172147
System.Diagnostics.Trace.WriteLine(FormattingUtils.XmlErrorPosition.RightToLeft);
173148
}
174-
}
175-
149+
}

src/Schematron/Diagnostic.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Schematron;
88
/// <see cref="Assert"/> or successful <see cref="Report"/> via the <c>@diagnostics</c> IDREFS
99
/// attribute. The <c>&lt;diagnostic&gt;</c> is stored at the schema level and referenced by id.
1010
/// </remarks>
11-
public class Diagnostic
12-
{
13-
/// <summary>Gets or sets the unique ID of this diagnostic (value of the <c>@id</c> attribute).</summary>
14-
public string Id { get; set; } = String.Empty;
15-
16-
/// <summary>Gets or sets the raw text content / message of this diagnostic element.</summary>
17-
public string Message { get; set; } = String.Empty;
18-
}
11+
/// <param name="Id">Gets or sets the unique ID of this diagnostic (value of the <c>@id</c> attribute).</param>
12+
/// <param name="Message">Gets or sets the raw text content / message of this diagnostic element.</param>
13+
public record Diagnostic(string Id, string Message);

0 commit comments

Comments
 (0)