Skip to content

[API Proposal]: Allow BeEquivalentTo to exclude all members of a certain type #3114

@dennisdoomen

Description

@dennisdoomen

Background and motivation

A shortcut to options.Excluding(mi => mi.Type == typeof(TimeSpan));

API Proposal

public abstract class SelfReferenceEquivalencyAssertionOptions<TSelf> : IEquivalencyOptions
    where TSelf : SelfReferenceEquivalencyAssertionOptions<TSelf>
{
    public TSelf Excluding<TMember>()
    {
    }
}

Also supports excluding all members whose type is assignable to IMyInterface

options.Excluding<IMyInterface>();

And excludeing all members whose type is a closed generic of Nullable<T>, i.e. it excludes int?, double?, etc.

options.Excluding(typeof(Nullable<>))

API Usage

Instead of options.Excluding(mi => mi.Type == typeof(TimeSpan));, you can do options.Excluding<TimeSpan>()

Alternative Designs

Maybe name it ExcludingMembersOfType<T>

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

api-approvedAPI was approved, it can be implemented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions