示例#1
0
        /// <summary>
        ///     Compile a function string ("sin(t, C)") into a Func&lt;double, double&gt;, connect it with the sample and store it.
        /// </summary>
        /// <param name="text">A string that represents a function that can be used to generate a waveform.</param>
        private void CompileFunction(string text)
        {
            IExpressionEvaluator eval = new ExpressionEvaluator(ExpressionLanguage.CSharp);
            var context = new EvalContext {
                S = this
            };
            EvalExpression <double, EvalContext> expression = eval.GetDelegate <double, EvalContext>(text);

            _compiledfunction = GetMethod(context, expression);
        }
示例#2
0
        /// <summary>
        ///     Since an EvalExpression can't take any parameters but takes all its information from its evaluation context object
        ///     we'll need a wrapper to create a convenient Func&lt;double, double&gt; to use for the calculations.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        private static Func <double, double> GetMethod(EvalContext context, EvalExpression <double, EvalContext> expr)
        {
            Func <double, double> ret = delegate(double t)
            {
                context.t = t;
                return(expr(context));
            };

            return(ret);
        }