internal Evaluator(
            string expression, Delegate method, int argsCount)
        {
            Debug.Assert(expression != null);
            Debug.Assert(argsCount >= 0);
            Debug.Assert(method != null);

            this.expression = expression;
            this.argsCount  = argsCount;
            this.Evaluate0  = Throw0;
            this.Evaluate1  = Throw1;
            this.Evaluate2  = Throw2;

            if (argsCount == 0)
            {
                this.Evaluate0 = (EvalFunc0 <T>)method;
                this.EvaluateN = (a => this.Evaluate0());
            }
            else if (argsCount == 1)
            {
                this.Evaluate1 = (EvalFunc1 <T>)method;
                this.EvaluateN = (a => this.Evaluate1(a[0]));
            }
            else if (argsCount == 2)
            {
                this.Evaluate2 = (EvalFunc2 <T>)method;
                this.EvaluateN = (a => this.Evaluate2(a[0], a[1]));
            }
            else
            {
                this.EvaluateN = (EvalFuncN <T>)method;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Adds the <see cref="EvalFuncN{T}"/> delegate
 /// to the <see cref="FunctionCollection{T}"/> with the
 /// function name, taken from real method name.</summary>
 /// <param name="target">
 /// <see cref="EvalFuncN{T}"/> instance to add.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="target"/> is null.</exception>
 /// <exception cref="ArgumentException">
 /// <paramref name="target"/> is not valid delegate
 /// to be added to the <see cref="FunctionCollection{T}"/>.
 /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the
 /// same name and same arguments count already exist
 /// in the collection (overload impossible).</exception>
 /// <remarks>Not available on .NET CF 2.0 because
 /// it's impossible to resolve method name.</remarks>
 public void Add(EvalFuncN <T> target)
 {
     AddFunc(FunctionFactory <T>
             .FromDelegate(target, true));
 }
Beispiel #3
0
 /// <summary>
 /// Adds the <see cref="EvalFuncN{T}"/> delegate
 /// to the <see cref="FunctionCollection{T}"/>
 /// with the specified function name.</summary>
 /// <param name="name">Function group name.</param>
 /// <param name="target">
 /// <see cref="EvalFuncN{T}"/> instance to add.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="target"/> is null.</exception>
 /// <exception cref="ArgumentException">
 /// <paramref name="target"/> is not valid delegate
 /// to be added to the <see cref="FunctionCollection{T}"/>.
 /// <br/>-or-<br/><see cref="FunctionInfo{T}"/> with the
 /// same name and same arguments count already exist
 /// in the collection (overload impossible).</exception>
 public void Add(string name, EvalFuncN <T> target)
 {
     AddFunc(name, FunctionFactory <T>
             .FromDelegate(target, true));
 }