Exemple #1
0
 /// <summary>
 /// Add the given rule to all nodes targetted by the facts it uses.
 /// If the targetted node path doesn't exists, creates it.
 /// </summary>
 /// <param name="rule">The rule to set to the child nodes.</param>
 public void AddRule(RuleInfo rule)
 {
     foreach (var path in rule.Facts)
     {
         var node = GetNode(path, true);
         node.Rules.Add(rule);
     }
 }
Exemple #2
0
        /// <summary>
        /// Loads a model into the engine under the optional root.
        /// </summary>
        /// <param name="model">The model to load in the engine.</param>
        /// <param name="root">Optional, defaults to empty string. The root
        /// where to put the model.</param>
        public void Load(object model, string root = "")
        {
            var objectMethods = new HashSet <string>(
                typeof(object).GetMethods().Select(m => m.Name));
            var methods = model.GetType().GetMethods().Where(
                m => !objectMethods.Contains(m.Name));

            foreach (var method in methods)
            {
                var rule = new RuleInfo(model, method);
                _rules.Add(rule.Name, rule);
                _root.AddRule(rule);
            }
        }