Skip to content

Refactor monolithic Semantics project into modular packages#63

Merged
matt-edmondson merged 243 commits intovectorsfrom
main
May 9, 2026
Merged

Refactor monolithic Semantics project into modular packages#63
matt-edmondson merged 243 commits intovectorsfrom
main

Conversation

@matt-edmondson
Copy link
Copy Markdown
Contributor

Summary

This PR restructures the Semantics project from a single monolithic assembly into three separate, focused NuGet packages: Semantics.Strings, Semantics.Paths, and Semantics.Quantities. This improves modularity, reduces dependencies for consumers who only need specific functionality, and establishes a cleaner architectural foundation.

Key Changes

  • Project Structure Reorganization

    • Created three new .csproj files: Semantics.Strings.csproj, Semantics.Paths.csproj, and Semantics.Quantities.csproj
    • Moved semantic string validation logic to Semantics.Strings/
    • Moved path-related types and validation to Semantics.Paths/
    • Moved physical quantities and units to Semantics.Quantities/
    • Added AssemblyInfo.cs and CompatibilitySuppressions.xml to each package
  • Validation Attributes Reorganization

    • Separated validation attributes into individual files organized by category
    • String validation attributes now in Semantics.Strings/Validation/Attributes/ with subdirectories:
      • Casing/ - case format validators (CamelCase, PascalCase, SnakeCase, etc.)
      • FirstClassTypes/ - validators for built-in .NET types
      • Format/ - line count and whitespace validators
      • Text/ - text pattern validators (regex, email, base64, etc.)
    • Path validation attributes in Semantics.Paths/Validation/Attributes/Path/
  • New Validation Attributes

    • Added missing string validators: IsKebabCaseAttribute, IsLowerCaseAttribute, IsPascalCaseAttribute, IsSnakeCaseAttribute, IsTitleCaseAttribute, IsUpperCaseAttribute
    • Added format validators: HasNonWhitespaceContentAttribute, IsEmptyOrWhitespaceAttribute, IsMultiLineAttribute, IsSingleLineAttribute
    • Added text validators: ContainsAttribute, EndsWithAttribute, IsBase64Attribute, IsEmailAddressAttribute, PrefixAndSuffixAttribute, RegexMatchAttribute, StartsWithAttribute
  • Test Expansion

    • Added new test files for improved coverage:
      • CasingAndContractsTests.cs, CasingValidatorsTests.cs
      • FirstClassAndFormatValidatorsTests.cs, LineCountValidatorsTests.cs
      • AcousticDirectionalityIndexTests.cs, AcousticImpedanceTests.cs, AcousticOperatorTests.cs
      • NuclearQuantitiesTests.cs, PhysicalDimensionTests.cs, PhysicalQuantityCoreTests.cs
      • Paths/DirectoryNameTests.cs, Paths/PathIntegrationTests.cs, Paths/RelativePathPropertyTests.cs
    • Removed FluentValidationAdapterTests.cs (replaced with internal ValidationAdapter.cs)
  • CI/CD Updates

    • Added .github/workflows/update-sdks.yml for automated SDK updates
    • Updated .github/workflows/dotnet.yml with improved build configuration
    • Updated .runsettings for coverage reporting
  • Cleanup

    • Removed SpecStory history files and derived cursor rules (AI assistant artifacts)
    • Removed .cursorignore and .cursorindexingignore files
    • Updated .gitignore to exclude SpecStory-related files

Implementation Details

  • Each package maintains its own validation infrastructure while sharing common base classes
  • Path types now include a new DirectoryName primitive type
  • Validation attributes are now granularly organized by concern, improving discoverability and maintainability
  • The modular structure allows consumers to depend only on the packages they need, reducing transitive dependencies

https://claude.ai/code/session_01HxA4AzzqEd3vdyDCFUDPSP

matt-edmondson and others added 30 commits August 16, 2025 17:18
This commit includes the following changes:
- Refactored project files to use the new SDK format, enhancing compatibility and maintainability.
- Updated `global.json` to reflect the latest versions of `ktsu.Sdk` and `MSTest.Sdk`.
- Removed outdated package versions from `Directory.Packages.props`, streamlining dependency management.
- Enhanced GitHub Actions workflows to allow manual triggers and improved caching for SonarQube.
- Updated unit tests to use `Assert.ThrowsExactly<TException>()` for more precise exception handling.

These modifications aim to improve project organization, ensure up-to-date dependencies, and enhance testing reliability.
This commit includes the following changes:
- Removed the `FluentValidation` dependency from various validation attributes, replacing it with a native validation approach.
- Updated validation logic to return `ValidationResult` objects for success and failure cases.
- Deleted the `FluentValidationAdapter` class and its associated tests, streamlining the validation framework.
- Adjusted multiple validation attributes to ensure they function correctly without the FluentValidation integration.

These modifications aim to simplify the validation framework and enhance maintainability by reducing external dependencies.
…on logic

This commit includes the following changes:
- Updated validation attributes to use constructor parameters for initialization, improving clarity and reducing boilerplate code.
- Refactored validation logic to return `ValidationResult` objects directly, ensuring consistent success and failure handling.
- Simplified the implementation of various validation adapters, including `ContainsValidator`, `EndsWithValidator`, and others, to streamline their functionality.

These modifications aim to improve the maintainability and readability of the validation framework.
This commit includes the following changes:
- Removed obsolete validation rules and README files related to the validation framework.
- Introduced new path-related classes, including `SemanticAbsolutePath`, `SemanticDirectoryPath`, and `SemanticFilePath`, to enhance path handling capabilities.
- Updated project files to reflect the new structure and added necessary interfaces for path validation.
- Improved organization of validation attributes by moving them to a dedicated directory for better maintainability.

These modifications aim to streamline the validation framework and enhance the overall path management functionality.
This commit introduces support for creating and manipulating semantic strings using read-only spans. Key changes include:
- Added `FromReadOnlySpan` methods in `ISemanticStringFactory` and `SemanticStringFactory` for improved performance.
- Updated `SemanticString` methods to utilize read-only spans for various operations, enhancing efficiency.
- Refactored validation attributes to ensure compatibility with new span-based methods.

These modifications aim to optimize string handling and validation processes within the framework.
This commit includes the following changes:
- Added suppression warnings for specific code analysis rules related to string handling in the project file.
- Simplified the `Remove` method in `SemanticString` by removing redundant parameter names for clarity.
- Adjusted formatting for improved readability in the `MoveNext` method.

These modifications aim to enhance code quality and maintainability within the string handling framework.
…operations

This commit updates the `SemanticString` class to improve performance by using `WeakString` for various methods that handle read-only spans. Key changes include:
- Modified `IndexOf`, `LastIndexOf`, `StartsWith`, `EndsWith`, and `Contains` methods to leverage `WeakString` instead of `AsSpan()`.
- Added conditional compilation for span support based on target frameworks.

These modifications aim to enhance efficiency in string operations while maintaining compatibility across different .NET versions.
This commit introduces a new polyfill for `ArgumentNullException.ThrowIfNull` to support older .NET versions. Additionally, it refactors the namespaces of various path-related classes and interfaces to `ktsu.Semantics.Paths` for improved organization and clarity. The changes include:

- Added `ArgumentNullExceptionPolyfill` for null argument validation.
- Updated namespaces in `SemanticAbsolutePath`, `SemanticDirectoryPath`, `SemanticFilePath`, `SemanticRelativePath`, and others to reflect the new structure.
- Adjusted method implementations in path classes to utilize the new polyfill where applicable.

These modifications aim to enhance code maintainability and ensure compatibility across different .NET versions.
…atibility

This commit adds a polyfill for `ArgumentNullException.ThrowIfNull` to support older .NET versions across various path-related classes. Key changes include:

- Integrated `ArgumentNullExceptionPolyfill` in `SemanticRelativePath`, `AbsoluteDirectoryPath`, `AbsoluteFilePath`, `DirectoryPath`, `RelativeDirectoryPath`, and `RelativeFilePath` implementations.
- Updated null checks to utilize the polyfill for compatibility with .NET versions prior to 6.0.

These modifications enhance the robustness of the path handling framework while ensuring backward compatibility.
…bility

This commit updates the `AsRelative` method in the `RelativeFilePath` class to include a conditional compilation directive that utilizes `ArgumentNullExceptionPolyfill.ThrowIfNull` for .NET versions prior to 6.0. This change ensures consistent null argument validation across different framework versions, enhancing the robustness of the path handling implementation.
…tibility

This commit introduces the `System.Memory` package for .NET Standard 2.0 support and adds several polyfills to enhance path handling across different .NET versions. Key changes include:

- Added `System.Memory` package reference in `Directory.Packages.props` and project files for .NET Standard 2.0.
- Implemented polyfills for `OperatingSystem` and `Path` methods to ensure compatibility with older .NET versions.
- Updated various path-related classes to utilize the new polyfills, improving functionality and consistency in path operations.

These modifications aim to enhance the robustness and compatibility of the path handling framework across different .NET versions.
…ation for older .NET versions

This commit updates the `AbsoluteDirectoryPath`, `DirectoryPath`, and `RelativeDirectoryPath` classes to include synchronous `GetContents` methods for compatibility with .NET versions prior to 2.1. The changes ensure that directory contents can be enumerated synchronously when asynchronous methods are not available, enhancing the framework's robustness across different .NET versions. Additionally, minor adjustments were made to the `PooledStringBuilder` class for consistency in handling directory separators.
This commit makes minor formatting adjustments across several files to enhance code clarity. Changes include removing unnecessary blank lines and aligning code indentation for conditional compilation directives. These modifications aim to improve the overall maintainability of the path handling framework while ensuring consistent coding standards.
… clarity

This commit updates the `SemanticDirectoryPath` class to rename the `Contents` property to `GetContents` for improved clarity. The method now consistently handles directory content retrieval, including error handling for access and existence checks. Additionally, the `GetContents` method is implemented synchronously across relevant directory path classes, ensuring compatibility with older .NET versions. Unused asynchronous method signatures have been removed from the `IDirectoryPath` interface to streamline the API.
…ysical dimensions and update test classes to static for consistency. This improves clarity and aligns with coding standards across the project.
…bute, and StartsWithAttribute classes

This commit updates the validation logic in the `ContainsAttribute`, `EndsWithAttribute`, and `StartsWithAttribute` classes to return more informative error messages when the input value is null or empty. Instead of returning a success result, the validation now clearly indicates the expected substring, suffix, or prefix that must be present in the value, improving user feedback and clarity in validation errors.
This commit deletes several outdated files, including the derived cursor rules, .gitignore, and various history documents, to streamline the project and remove unnecessary clutter. The removal of these files helps maintain a cleaner codebase and improves overall project organization.
…hod naming and enhance error handling. The `Contents` property has been renamed to `GetContents` for clarity, and synchronous handling has been implemented to ensure compatibility with older .NET versions.
… improved performance and reliability. This change ensures that the regex operation does not hang indefinitely by setting a one-second timeout, enhancing the overall validation process.
This commit introduces two new test classes: `CasingAndContractsTests` and `RegexMatchAttributeTests`. The `CasingAndContractsTests` class validates camel case, pascal case, boolean, and contract strings, ensuring correct behavior for valid and invalid inputs. The `RegexMatchAttributeTests` class tests regex patterns for various string types, including handling invalid patterns and validating case insensitivity and multiline anchors. These additions enhance the test coverage for string semantics and validation logic.
This commit introduces two new test classes: `CasingValidatorsTests` and `LineCountValidatorsTests`. The `CasingValidatorsTests` class validates various casing formats, including upper case, lower case, title case, sentence case, snake case, kebab case, and macro case, ensuring correct behavior for valid and invalid inputs. The `LineCountValidatorsTests` class checks for exact, minimum, and maximum line counts in strings, enhancing the test coverage for string semantics and validation logic.
This commit introduces a new test class, `FirstClassAndFormatValidatorsTests`, which includes unit tests for multiple validators such as `IsDateTime`, `IsDecimal`, `IsDouble`, `IsGuid`, `IsInt32`, `IsIpAddress`, `IsTimeSpan`, `IsUri`, `IsVersion`, `HasNonWhitespaceContent`, `IsEmptyOrWhitespace`, `IsSingleLine`, and `IsMultiLine`. Each validator is tested for valid, invalid, and empty inputs, enhancing the test coverage for string semantics and validation logic.
This commit updates the Exposure class to use CoulombPerKilogram instead of Coulomb for exposure calculations. Additionally, new unit tests have been added for various nuclear quantities, including AbsorbedDose and EquivalentDose, to ensure correct conversions and calculations. The test suite now includes comprehensive checks for exposure-related functionalities, enhancing overall test coverage.
This commit adds the installation of the `dotnet-coverage` tool in the GitHub Actions workflow to facilitate code coverage collection during tests. It also updates the SonarQube scanner commands to improve coverage reporting and modifies the `Invoke-DotNetTest` function to utilize the new coverage tool. Additionally, the test project configuration is updated to show test failures and details, enhancing the overall testing and reporting capabilities.
github-actions Bot and others added 28 commits March 16, 2026 04:36
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 9.23.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 9.24.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 10.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: MSTest.Sdk
  dependency-version: 4.2.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 10.1.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 10.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: MSTest.Sdk
  dependency-version: 4.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 10.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
---
updated-dependencies:
- dependency-name: Polyfill
  dependency-version: 10.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant