Beispiel #1
0
    /// <summary>
    /// Computes the expression and returns a result.
    /// </summary>
    /// <param name="tolerance">The tolerance.</param>
    /// <param name="dataFinder">The data finder for the arguments with which to invoke execution of the expression.</param>
    /// <returns>
    /// The computed result, or, if the expression is not recognized correctly, the expression as a <see cref="string" />.
    /// </returns>
    public object Compute(Tolerance?tolerance, IDataFinder dataFinder)
    {
        this.RequiresNotDisposed();

        if (!RecognizedCorrectly)
        {
            return(initialExpression);
        }

        var pars = new List <object>();

        _ = Requires.NotNull(
            dataFinder,
            nameof(dataFinder));

        foreach (ParameterContext p in parametersRegistry?.Dump() ?? Array.Empty <ParameterContext>())
        {
            if (!dataFinder.TryGetData(p.Name, out var data))
            {
                data = null;
            }

            pars.Add(data);
        }

        return(pars.Any(p => p == null) ? initialExpression : Compute(tolerance, pars.ToArray()));
    }