/// <summary> /// Builds the expression decision definition /// </summary> /// <returns>Decision definition built</returns> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the expression or output variable is not defined in builder</exception> protected internal override IDmnDecision Build() { if (IsBuilt) { throw Logger.Error <DmnBuilderException>("Decision is already built"); } if (OutputVariableInternal == null) { throw Logger.Error <DmnBuilderException>($"Missing output variable for expression decision {Name}"); } if (string.IsNullOrWhiteSpace(Expression)) { throw Logger.Error <DmnBuilderException>($"Missing expression for expression decision {Name}"); } //create var expressionDecision = new DmnExpressionDecision( Name, Expression, OutputVariableInternal.GetResultOrBuild(), RequiredInputs.Select(i => Variables[i].GetResultOrBuild()).ToArray(), RequiredDecisions.Select(d => Decisions[d].GetResultOrBuild()).ToArray()); ResultInternal = expressionDecision; return(expressionDecision); }
/// <summary> /// Sets the output variable to store the result of the decision expression evaluation to /// </summary> /// <param name="variable">Reference to the variable used to store the expression decision output</param> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception> /// <exception cref="ArgumentNullException">When the <paramref name="variable"/> is null</exception> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="variable"/> can't be found in <see cref="VariableCatalog"/></exception> private void SetOutput(Variable.Ref variable) { if (IsBuilt) { throw Logger.Error <DmnBuilderException>("Decision is already built"); } if (variable == null) { throw new ArgumentNullException(nameof(variable)); } OutputVariableInternal = Variables[variable] ?? throw Logger.Error <DmnBuilderException>($"Can't get the variable from reference {variable.Name}"); OutputVariableInternal.AddValueSetter($"Expression Decision {Name}"); }