Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Rule.cs
1using System;
2using System.Xml;
4
6{
10 [TypeName(TypeNameSerialization.LocalName)]
11 public abstract class Rule
12 {
16 public const string RuleNamespace = "http://waher.se/Schema/Provisioning/Rules.xsd";
17
18 private Rule[] childRules = null;
19
23 public Rule()
24 {
25 }
26
30 [DefaultValueNull]
32 {
33 get => this.childRules;
34 set => this.childRules = value;
35 }
36
42 public virtual bool? Evaluate(Context Context)
43 {
44 bool? Result;
45
46 if (!(this.childRules is null))
47 {
48 foreach (Rule Rule2 in this.childRules)
49 {
50 Result = Rule2.Evaluate(Context);
51 if (Result.HasValue)
52 return Result;
53 }
54 }
55
56 return null;
57 }
58
63 public void AddChildRule(Rule Rule)
64 {
65 if (this.childRules is null)
66 this.childRules = new Rule[] { Rule };
67 else
68 {
69 int c = this.childRules.Length;
70 Array.Resize(ref this.childRules, c + 1);
71 this.childRules[c] = Rule;
72 }
73 }
74
79 public abstract void Export(XmlWriter Output);
80
85 protected virtual void ExportChildren(XmlWriter Output)
86 {
87 if (!(this.childRules is null))
88 {
89 foreach (Rule Rule in this.childRules)
90 Rule.Export(Output);
91 }
92 }
93 }
94}
Abstract base class for rules.
Definition: Rule.cs:12
abstract void Export(XmlWriter Output)
Exports the rule.
void AddChildRule(Rule Rule)
Adds a child rule.
Definition: Rule.cs:63
Rule[] ChildRules
Child rules, if applicable.
Definition: Rule.cs:32
const string RuleNamespace
http://waher.se/Schema/Provisioning/Rules.xsd
Definition: Rule.cs:16
Rule()
Abstract base class for decisions.
Definition: Rule.cs:23
virtual void ExportChildren(XmlWriter Output)
Exports child rules.
Definition: Rule.cs:85
virtual ? bool Evaluate(Context Context)
Tries to evaluate the rule.
Definition: Rule.cs:42
TypeNameSerialization
How the type name should be serialized.