-
-
Notifications
You must be signed in to change notification settings - Fork 539
/
IncludeMemberByPathSelectionRule.cs
37 lines (31 loc) · 1.23 KB
/
IncludeMemberByPathSelectionRule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections.Generic;
using System.Linq;
using FluentAssertions.Common;
namespace FluentAssertions.Equivalency.Selection
{
/// <summary>
/// Selection rule that includes a particular property in the structural comparison.
/// </summary>
internal class IncludeMemberByPathSelectionRule : SelectMemberByPathSelectionRule
{
private readonly MemberPath pathToInclude;
public IncludeMemberByPathSelectionRule(string pathToInclude) : base(pathToInclude)
{
this.pathToInclude = new MemberPath(pathToInclude);
}
public override bool IncludesMembers => true;
protected override IEnumerable<SelectedMemberInfo> OnSelectMembers(IEnumerable<SelectedMemberInfo> selectedMembers,
string currentPath, ISubjectInfo context)
{
var matchingMembers =
from member in context.RuntimeType.GetNonPrivateMembers()
where pathToInclude.IsParentOrChildOf(currentPath.Combine(member.Name))
select member;
return selectedMembers.Concat(matchingMembers).ToArray();
}
public override string ToString()
{
return "Include member root." + pathToInclude;
}
}
}