-
Notifications
You must be signed in to change notification settings - Fork 732
[API Proposal]: Support for selecting multiple properties in single expression. #2479
Copy link
Copy link
Closed
Labels
api-approvedAPI was approved, it can be implementedAPI was approved, it can be implementedenhancement
Description
Background and motivation
If I write assertion this way:
actualEnv.Should().BeEquivalentTo(env, _ => _.Excluding(_ => new { _.Id, _.Creator, _.LastEditor }));
the exception is thrown:
System.ArgumentException : Expression <new <>f__AnonymousType0`3(Id = _.Id, Creator = _.Creator, LastEditor = _.LastEditor)> cannot be used to select a member. (Parameter 'expression')
So I have to write it slightly more verbose.
actualEnv.Should().BeEquivalentTo(env, _ => _.Excluding(_ => _.Id).Excluding(_ => _.Creator).Excluding(_ => _.LastEditor));
API Proposal
So, my proposal is to treat expression for anonymous object creation as an enumeration of properties to exclude.
For example EF Core uses this approach for defining composite key.
API Usage
a.Shoul().BeEquivalentTo(b, _ => _.Excluding(b => new { b.Prop1, ...., b.PropN }));
Alternative Designs
No response
Risks
No response
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
No
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved, it can be implementedAPI was approved, it can be implementedenhancement