Exemplo n.º 1
0
        /// <summary>
        /// Sets the <paramref name="inputExpression">input expression</paramref> for the input referenced by <paramref name="inputRef"/>
        /// </summary>
        /// <remarks>
        /// When the expression is null or whitespace the table input will not be used for the rule (will be removed when it was already defined before).
        /// When the expression is "valid" and the input expression has been defined before, it will override it
        /// </remarks>
        /// <param name="inputRef">Reference to decision table input</param>
        /// <param name="inputExpression">Input evaluation expression</param>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        /// <exception cref="ArgumentNullException">Throws <see cref="ArgumentNullException"/> when the <paramref name="inputRef"/> is null</exception>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="inputRef"/> is not recognized as the valid table input</exception>
        private void SetInput(TableInput.Ref inputRef, string inputExpression)
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>("Table rule is already built");
            }

            if (inputRef == null)
            {
                throw new ArgumentNullException(nameof(inputRef));
            }
            if (!AllTableInputs.ContainsKey(inputRef))
            {
                throw Logger.Error <DmnBuilderException>("Input reference is not valid for current table");
            }

            if (string.IsNullOrWhiteSpace(inputExpression))
            {
                if (InputsInternal.ContainsKey(inputRef))
                {
                    InputsInternal.Remove(inputRef);
                }
            }
            else
            {
                InputsInternal[inputRef] = inputExpression;
            }
        }