Skip to content

[API Proposal]: Support for selecting multiple properties in single expression. #2479

@voroninp

Description

@voroninp

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions