[]
        
(Showing Draft Content)

Create Custom Function

Expression Editor provides various built-in functions to create expressions for your applications. Furthermore, it allows you to define custom functions according to your application’s requirement. The AddFunction method of C1ExpressionEditor class allows you to add custom functions to Expression Editor. This custom function gets added to the ExpressionEditor engine and is accessible at runtime by C1ExpreesionEditor for performing calculations.

The following code demonstrates how a custom function is created and added to the Expression Editor panel:

private void SetupCustomFunction()
{
  // Define the custom Function
  ExpressionItem factItem = new ExpressionItem(
  // Name of Custom Function
  "Factorial",
  // Syntax(structure) of Custom Function
  "Factorial()",
  // Description of the Custom Function
  "Returns the product of an integer and all the integers below it.",
  // Determines the type of Expression Item
  ItemType.MathFuncs
  );
  // Define the type of argument the function will take
  factItem.Arguments.Add(new Argument("number", typeof(System.Double)));
  // Add the custom function to the Engine
  expressionEditor.Engine.AddFunction([factItem], Factorial, 1, 1);
}