-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrOperator.cs
More file actions
55 lines (44 loc) · 1.21 KB
/
OrOperator.cs
File metadata and controls
55 lines (44 loc) · 1.21 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
namespace NetEvolve.FluentValue.Operators;
using System;
using System.Text;
using NetEvolve.FluentValue;
using NetEvolve.FluentValue.Constraints;
internal sealed class OrOperator : ConstraintBase, IOperator
{
private readonly IConstraint _left;
private IConstraint? _right;
internal OrOperator(IConstraint left)
{
ArgumentNullException.ThrowIfNull(left);
_left = left;
}
public override bool IsSatisfiedBy(object? value)
{
if (_right is null)
{
throw new InvalidOperationException();
}
return _left.IsSatisfiedBy(value) || _right.IsSatisfiedBy(value);
}
public IConstraint SetConstraint(IConstraint constraint)
{
ArgumentNullException.ThrowIfNull(constraint);
if (_right is NotOperator notOperator)
{
_ = notOperator.SetConstraint(constraint);
return this;
}
_right = constraint;
return this;
}
public override void SetDescription(StringBuilder builder)
{
_left.SetDescription(builder);
if (_right is null)
{
return;
}
_ = builder.Append(" or");
_right.SetDescription(builder);
}
}