Display conditions - Implemented lists in the core, UI needs more work

This commit is contained in:
Robert committed 2020-08-12 17:22:43 +02:00
1 parent cd02a422fe
commit c0e1e60e5e
13 files changed
+288 -84

No files matched your search

@@ -37,9 +37,12 @@ namespace Artemis.Core.Models.Profile.Conditions
public override bool Evaluate()
{
// If there are less than two children, ignore the boolean operator
if (Children.Count <= 2)
return Children.All(c => c.Evaluate());
// Empty groups are always true
if (Children.Count == 0)
return true;
// Groups with only one child ignore the boolean operator
if (Children.Count == 1)
return Children[0].Evaluate();
switch (BooleanOperator)
{
@@ -56,6 +59,25 @@ namespace Artemis.Core.Models.Profile.Conditions
}
}
public override bool EvaluateObject(object target)
{
// Empty groups are always true
if (Children.Count == 0)
return true;
// Groups with only one child ignore the boolean operator
if (Children.Count == 1)
return Children[0].EvaluateObject(target);
return BooleanOperator switch
{
BooleanOperator.And => Children.All(c => c.EvaluateObject(target)),
BooleanOperator.Or => Children.Any(c => c.EvaluateObject(target)),
BooleanOperator.AndNot => Children.All(c => !c.EvaluateObject(target)),
BooleanOperator.OrNot => Children.Any(c => !c.EvaluateObject(target)),
_ => throw new ArgumentOutOfRangeException()
};
}
internal override void ApplyToEntity()
{
DisplayConditionGroupEntity.BooleanOperator = (int) BooleanOperator;