Skip to content

Conversation

@alexanderlinne
Copy link
Collaborator

@alexanderlinne alexanderlinne commented Jan 9, 2026

This PR eliminates significant code duplication in the fluent API by restructuring the class hierarchy:

Before: Generic classes like TypesShould<TRuleTypeShouldConjunction, TRuleType> implemented all methods and used ConjunctionFactory.Create() with reflection to instantiate the next fluent element. This led to:

  • The same predicate/condition methods duplicated across GivenXXXThat and ShouldRelateToXXXThat classes
  • Runtime reflection for instantiation

After:

  • Abstract base classes (e.g., AddTypePredicate<TNextElement, TRelatedType, TRuleType>, AddTypeCondition<TNextElement, TRuleType>) contain the shared method implementations
  • Sealed leaf classes (e.g., GivenTypesThat, TypesShould) inherit from these bases and implement a simple CreateNextElement() factory method that directly instantiates the next class

Benefits:

  • ~3,000 lines of code removed
  • No more reflection-based instantiation in the fluent chain
  • Sealed classes prevent unintended inheritance and enable compiler optimizations
  • Single source of truth for each fluent method

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 86.15385% with 90 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.35%. Comparing base (92ae901) to head (c767974).

Files with missing lines Patch % Lines
.../Members/MethodMembers/AddMethodMemberCondition.cs 50.00% 18 Missing ⚠️
.../Members/MethodMembers/AddMethodMemberPredicate.cs 48.57% 18 Missing ⚠️
...T/Fluent/Syntax/Elements/Types/AddTypePredicate.cs 73.43% 17 Missing ⚠️
...T/Fluent/Syntax/Elements/Types/AddTypeCondition.cs 87.32% 9 Missing ⚠️
...uent/Syntax/Elements/Members/AddMemberCondition.cs 78.94% 4 Missing ⚠️
...uent/Syntax/Elements/Members/AddMemberPredicate.cs 76.47% 4 Missing ⚠️
...lements/Members/FieldMembers/FieldMembersShould.cs 0.00% 4 Missing ⚠️
...ents/Members/FieldMembers/GivenFieldMembersThat.cs 0.00% 4 Missing ⚠️
...ers/FieldMembers/ShouldRelateToFieldMembersThat.cs 0.00% 4 Missing ⚠️
...opertyMembers/ShouldRelateToPropertyMembersThat.cs 0.00% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #444      +/-   ##
==========================================
+ Coverage   73.69%   77.35%   +3.66%     
==========================================
  Files         260      275      +15     
  Lines       16463    14411    -2052     
  Branches     1337     1337              
==========================================
- Hits        12132    11148     -984     
+ Misses       3912     2844    -1068     
  Partials      419      419              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
@alexanderlinne alexanderlinne force-pushed the single-fluent-interface-implementation branch from 7183fe8 to bcc8a02 Compare January 9, 2026 14:11
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.

4 participants