-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathObjectProvider.cs
More file actions
76 lines (64 loc) · 1.93 KB
/
ObjectProvider.cs
File metadata and controls
76 lines (64 loc) · 1.93 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.Collections.Generic;
using System.Linq;
using ArchUnitNET.Domain;
namespace ArchUnitNET.Fluent
{
internal class ObjectProvider<T> : ISizedObjectProvider<T>
where T : ICanBeAnalyzed
{
private readonly List<T> _objects;
public ObjectProvider()
: this(new List<T>()) { }
public ObjectProvider(IEnumerable<T> objects)
{
_objects = objects.ToList();
Description = string.Join(" or ", _objects.Select(obj => $"\"{obj.FullName}\""));
}
public string Description { get; }
public int Count => _objects.Count;
public IEnumerable<T> GetObjects(Architecture architecture)
{
return _objects;
}
public string FormatDescription(
string emptyDescription,
string singleDescription,
string multipleDescription
)
{
switch (Count)
{
case 0:
return emptyDescription;
case 1:
return $"{singleDescription} {Description}";
}
return $"{multipleDescription} {Description}";
}
private bool Equals(ObjectProvider<T> other)
{
return _objects.SequenceEqual(other._objects);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return obj.GetType() == GetType() && Equals((ObjectProvider<T>)obj);
}
public override int GetHashCode()
{
return _objects != null
? _objects.Aggregate(
0,
(current, obj) => (current * 397) ^ (obj?.GetHashCode() ?? 0)
)
: 0;
}
}
}