Skip to content

feat: replace Expression with Func for memberSelector#651

Merged
vbreuss merged 2 commits intomainfrom
topic/expression-to-func-for-memberselector
Jun 22, 2025
Merged

feat: replace Expression with Func for memberSelector#651
vbreuss merged 2 commits intomainfrom
topic/expression-to-func-for-memberselector

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Jun 22, 2025

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.

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.
@vbreuss vbreuss self-assigned this Jun 22, 2025
Copilot AI review requested due to automatic review settings June 22, 2025 04:51
@vbreuss vbreuss added the enhancement New feature or request label Jun 22, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 extra string parameter via CallerArgumentExpression.
  • Introduced MemberAccessor.FromFuncAsMemberAccessor with ExtractMemberPath to parse the lambda expression text.
  • Updated all For, Which, and Whose implementations 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);

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 22, 2025

Test Results

    4 files   -     34      4 suites   - 34   26s ⏱️ - 2m 13s
  897 tests  - 12 749    896 ✅  - 12 748  1 💤  - 1  0 ❌ ±0 
2 577 runs   - 35 403  2 576 ✅  - 35 402  1 💤  - 1  0 ❌ ±0 

Results for commit 0f8d425. ± Comparison against base commit 27c997b.

♻️ This comment has been updated with latest results.

@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss enabled auto-merge (squash) June 22, 2025 05:19
@vbreuss vbreuss merged commit 7d6a7be into main Jun 22, 2025
13 checks passed
@vbreuss vbreuss deleted the topic/expression-to-func-for-memberselector branch June 22, 2025 05:22
@github-actions
Copy link
Copy Markdown
Contributor

This is addressed in release v2.18.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants