![]() |
bcParser.NET
Math Parser for .NET
|
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...
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... | |
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());
| 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.
| p | The list of parametes that this function takes. |
Implemented in Bestcode.MathParser.ZeroParameterFunc, Bestcode.MathParser.OneParameterFunc, and Bestcode.MathParser.TwoParameterFunc.
1.8.11