-
Notifications
You must be signed in to change notification settings - Fork 731
Add Excluding by type with inheritance support #3115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| public class ExcludingByType | ||
| { | ||
| [Fact] | ||
| public void When_excluding_members_by_type_it_should_exclude_exact_type_matches() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot don't use terms like "when" and "should", but instead use a current or future tense form for all test name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed all test methods to use present/future tense without "when" and "should" (commit edeadd1).
Src/FluentAssertions/Equivalency/Selection/ExcludeMemberByTypeSelectionRule.cs
Show resolved
Hide resolved
dennisdoomen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also update the objectgraphs.md and releases.md
Src/FluentAssertions/Equivalency/Selection/ExcludeMemberByTypeSelectionRule.cs
Show resolved
Hide resolved
Test Results 37 files ± 0 37 suites ±0 2m 53s ⏱️ +5s Results for commit 56a159e. ± Comparison against base commit d73f064. This pull request removes 10 and adds 28 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Updated both |
Qodana for .NET5 new problems were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
…by type Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
…hould" Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
6fb54bc to
1b5e9a0
Compare
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
1b5e9a0 to
4033707
Compare
Pull Request Test Coverage Report for Build 20550527439Details
💛 - Coveralls |
8231fea to
c6fcbe4
Compare
Tests/FluentAssertions.Equivalency.Specs/SelectionRulesSpecs.ExcludingByType.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Equivalency.Specs/SelectionRulesSpecs.ExcludingByType.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Equivalency/Selection/ExcludeMemberByTypeSelectionRule.cs
Show resolved
Hide resolved
c6fcbe4 to
56a159e
Compare
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
Summary
This PR implements the API proposal from #2390 to add a cleaner, more intuitive way to exclude all members of a certain type from structural equivalency assertions, with full support for inheritance and generic type hierarchies.
Motivation
Previously, to exclude all members of a specific type (e.g.,
TimeSpan), you had to write verbose predicate expressions:For interfaces, the syntax was even more complex:
And for open generic types like
Nullable<>, it was quite cumbersome:Changes
This PR adds two new methods to
SelfReferenceEquivalencyOptions<TSelf>:1. Generic Method:
Excluding<TMember>()2. Type Parameter Method:
Excluding(Type type)Features
Type Matching with Inheritance Support
For non-sealed types, the exclusion includes all derived types:
Sealed Type Matching
For sealed types (like
string), only exact matches are excluded:Interface and Abstract Type Support
For interfaces and abstract types, all implementing/derived types are excluded:
Open Generic Type Matching with Full Inheritance Support
Supports excluding all closed generics and types deriving from them:
This includes:
class ClosedGeneric : OpenGeneric<int>class DerivedOpenGeneric<T> : OpenGeneric<T>class ClosedDerivedGeneric : DerivedOpenGeneric<int>Multiple Exclusions
Methods can be chained for excluding multiple types:
Works at All Nesting Levels
Exclusions apply throughout the entire object graph, including nested objects and collections.
Implementation Details
ExcludeMemberByTypeSelectionRuleclass that implementsIMemberSelectionRulememberType == targetType)targetType.IsAssignableFrom(memberType))objectgraphs.mdandreleases.mdTesting
Breaking Changes
None. This is a purely additive change that maintains full backward compatibility.
Fixes #2390
Original prompt
Fixes #3114
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.