bcParser.NET
Math Parser for .NET
Public Member Functions | List of all members
Bestcode.MathParser.IFunction Interface Reference

IFunction interface represents a user defined callback function that takes n parameters. During evaluation of an expression, MathParser calls

IFunction.Run(IParameter[] p)

to request the value of the function when it takes parameters listed in p.

For example, a user could define a function like this:

public class MyFunc implements IFunction {
   public IConvertible Run(IParameter[] p){
     return do_something_with_params( p );
   }

   public int GetNumberOfParams(){
     return 3;
   }
}


Another user defined function "if" could be used as "if(1,3,4)". In this case, implementation of IFunction.Run(IParameter[]) could return 3.0 if first parameter is >0 and it could return 4.0 if first parameter is 0 (false, to mimic "if" behavior).

More...

Inheritance diagram for Bestcode.MathParser.IFunction:
Bestcode.MathParser.OneParameterFunc Bestcode.MathParser.TwoParameterFunc Bestcode.MathParser.ZeroParameterFunc

Public Member Functions

IConvertible Run (IParameter[] p)
 This method is where the user defined function logic is implemented. It computes the value based on the parameters passed in and returns it. Return value is a either Double or String or it is Convertible to one of them using the Convert class. More...
 
int GetNumberOfParams ()
 This method returns the length of the parameters array that will be passed to the Run(IParameter[]) method.
For example, for a function like F(X, Y, Z), this function should return 3. This value is used to verify syntax during parsing rather then leaving number of parameter verification to the evaluation time to individual functions. More...
 

Detailed Description

IFunction interface represents a user defined callback function that takes n parameters. During evaluation of an expression, MathParser calls

IFunction.Run(IParameter[] p)

to request the value of the function when it takes parameters listed in p.

For example, a user could define a function like this:

public class MyFunc implements IFunction {
   public IConvertible Run(IParameter[] p){
     return do_something_with_params( p );
   }

   public int GetNumberOfParams(){
     return 3;
   }
}


Another user defined function "if" could be used as "if(1,3,4)". In this case, implementation of IFunction.Run(IParameter[]) could return 3.0 if first parameter is >0 and it could return 4.0 if first parameter is 0 (false, to mimic "if" behavior).

User defined functions can be registered using CreateFunc method of MathParser. Example:
mathParser.CreateFunc("myfunc", new MyFunc());

Member Function Documentation

int Bestcode.MathParser.IFunction.GetNumberOfParams ( )

This method returns the length of the parameters array that will be passed to the Run(IParameter[]) method.
For example, for a function like F(X, Y, Z), this function should return 3. This value is used to verify syntax during parsing rather then leaving number of parameter verification to the evaluation time to individual functions.

Implemented in Bestcode.MathParser.ZeroParameterFunc, Bestcode.MathParser.OneParameterFunc, and Bestcode.MathParser.TwoParameterFunc.

IConvertible Bestcode.MathParser.IFunction.Run ( IParameter[]  p)

This method is where the user defined function logic is implemented. It computes the value based on the parameters passed in and returns it. Return value is a either Double or String or it is Convertible to one of them using the Convert class.

Parameters
pThe list of parametes that this function takes.
Returns

Implemented in Bestcode.MathParser.ZeroParameterFunc, Bestcode.MathParser.OneParameterFunc, and Bestcode.MathParser.TwoParameterFunc.