feat: replace Expression with Func for memberSelector#651
Merged
Conversation
The `memberSelector` in `For`/`Which`/`Whose` now accepts a `Func<T, TMember?>` instead of `Expression<Func<T, TMember?>>` which allows more use cases to be met.
There was a problem hiding this comment.
Pull Request Overview
This PR replaces expression-based member selectors with simple Func<T,TMember?> delegates for For/Which/Whose methods, adding [CallerArgumentExpression] to capture the member path and a new FromFuncAsMemberAccessor helper.
- Changed API signatures in tests and source to use
Func<T, TMember?>and an extrastringparameter viaCallerArgumentExpression. - Introduced
MemberAccessor.FromFuncAsMemberAccessorwithExtractMemberPathto parse the lambda expression text. - Updated all
For,Which, andWhoseimplementations to call the new accessor and pass the captured expression string.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/aweXpect.Core.Api.Tests/Expected/aweXpect.Core_netstandard2.0.txt | Updated expected API to include FromFuncAsMemberAccessor and CallerArgumentExpression parameters. |
| Tests/aweXpect.Core.Api.Tests/Expected/aweXpect.Core_net8.0.txt | Same as above for .NET 8.0 |
| Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt | Updated For extension to use Func selector and CallerArgumentExpression. |
| Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt | Same as above for .NET 8.0 |
| Source/aweXpect/That/ThatGeneric.For.cs | Switched For to use Func<T,TMember?>, added [CallerArgumentExpression], and updated accessor. |
| Source/aweXpect.Core/Results/AndOrWhichResult.cs | Updated Which/AndWhich to Func-based selectors and CallerArgumentExpression. |
| Source/aweXpect.Core/Results/AndOrWhoseResult.cs | Updated Whose/AndWhose to Func-based selectors and CallerArgumentExpression. |
| Source/aweXpect.Core/Delegates/ThatDelegateThrows.Whose.cs | Updated Whose on delegates to use Func-based selector with CallerArgumentExpression. |
| Source/aweXpect.Core/Core/MemberAccessor.cs | Added FromFuncAsMemberAccessor, ExtractMemberPath, and XML doc for the new method. |
Comments suppressed due to low confidence (3)
Source/aweXpect/That/ThatGeneric.For.cs:18
- [nitpick] The parameter name 'doNotPopulateThisValue' is unclear to API consumers; consider renaming it to something like 'memberSelectorExpression' to better convey its purpose.
[CallerArgumentExpression("memberSelector")] string doNotPopulateThisValue = "")
Source/aweXpect.Core/Core/MemberAccessor.cs:66
- Add XML documentation for 'ExtractMemberPath' explaining the expected format of 'name' (i.e., the lambda expression text) and what the returned string represents.
private static string ExtractMemberPath(string name)
Source/aweXpect.Core/Core/MemberAccessor.cs:69
- The logic in 'ExtractMemberPath' is somewhat brittle and may not handle nested or more complex expressions correctly; consider simplifying the algorithm or adding inline comments to clarify each step.
int idx = name.IndexOf("=>", StringComparison.Ordinal);
Contributor
|
Contributor
|
This is addressed in release v2.18.0. |
This was referenced Sep 1, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The
memberSelectorinFor/Which/Whosenow accepts aFunc<T, TMember?>instead ofExpression<Func<T, TMember?>>which allows more use cases to be met.