Ejemplo n.º 1
0
        /// <summary>
        /// Creates a pattern element that represents a match over results of the source element.
        /// </summary>
        /// <param name="declaration">Declaration that references the pattern.</param>
        /// <param name="conditions">Condition elements that represent conditions applied to the elements matched by the pattern.</param>
        /// <param name="source">Source of the elements matched by the pattern. If it's <c>null</c>, the pattern matches facts in rules engine's working memory.</param>
        /// <returns>Created element.</returns>
        public static PatternElement Pattern(Declaration declaration, IEnumerable <ConditionElement> conditions, PatternSourceElement source)
        {
            if (declaration == null)
            {
                throw new ArgumentNullException(nameof(declaration), "Pattern declaration not provided");
            }
            if (conditions == null)
            {
                throw new ArgumentNullException(nameof(conditions), "Pattern conditions not provided");
            }

            var element = new PatternElement(declaration, conditions, source);

            declaration.Target = element;
            return(element);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a pattern element that represents a match over results of the source element.
        /// </summary>
        /// <param name="type">Type of elements matched by the pattern.</param>
        /// <param name="name">Pattern name.</param>
        /// <param name="conditions">Condition elements that represent conditions applied to the elements matched by the pattern.</param>
        /// <param name="source">Source of the elements matched by the pattern. If it's <c>null</c>, the pattern matches facts in rules engine's working memory.</param>
        /// <returns>Created element.</returns>
        public static PatternElement Pattern(Type type, string name, IEnumerable <ConditionElement> conditions, PatternSourceElement source)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type), "Pattern type not provided");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name), "Pattern name not provided");
            }

            var declaration = new Declaration(type, name);
            var element     = Pattern(declaration, conditions, source);

            return(element);
        }