added Toolkit.UI.Avalonia
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Metadata;
|
||||
using Toolkit.UI.Avalonia;
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ConditionalExpression :
|
||||
AvaloniaObject,
|
||||
ICondition
|
||||
{
|
||||
public static readonly StyledProperty<ConditionCollection> ConditionsProperty =
|
||||
AvaloniaProperty.Register<ConditionalExpression, ConditionCollection>(nameof(Conditions));
|
||||
|
||||
public static readonly StyledProperty<ForwardChaining> ForwardChainingProperty =
|
||||
AvaloniaProperty.Register<ConditionalExpression, ForwardChaining>(nameof(ForwardChaining));
|
||||
|
||||
public ConditionalExpression() =>
|
||||
SetValue(ConditionsProperty, []);
|
||||
|
||||
[Content]
|
||||
public ConditionCollection Conditions =>
|
||||
GetValue(ConditionsProperty);
|
||||
|
||||
public ForwardChaining ForwardChaining
|
||||
{
|
||||
get => GetValue(ForwardChainingProperty);
|
||||
set => SetValue(ForwardChainingProperty, value);
|
||||
}
|
||||
|
||||
public bool Evaluate()
|
||||
{
|
||||
bool result = false;
|
||||
foreach (ComparisonCondition operation in this.Conditions)
|
||||
{
|
||||
result = operation.Evaluate();
|
||||
|
||||
if (result == false && ForwardChaining == ForwardChaining.And)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (result == true && ForwardChaining == ForwardChaining.Or)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user