This example shows how to add a custom function. First, you need to create a function:
...
public static decimal MySum(object value)
{
if (!ListExt.IsList(value))
return Stimulsoft.Base.Helpers.StiValueHelper.TryToDecimal(value);
return Stimulsoft.Data.Functions.Funcs.SkipNulls(ListExt.ToList(value))
.TryCastToDecimal()
.Sum();
}
...
Next, use
AddFunction()
to add this function to
StiFunctions
:
...
private void AddCustomFunction()
{
StiFunctions.AddFunction(
"My Category", "MySum", "description",
typeof(MyClass),
typeof(decimal),
"Calculates a sum of the specified set of values.",
new[] { typeof(object) },
new[] { "values" },
new[] { "A set of values" }).UseFullPath = false;
}
...
After that, you can use
AddCustomFunction()
in the main class after component initialization:
...
public FormMain()
{
InitializeComponent();
AddCustomFunction();
}
...
In the screenshot below you can see the result of the sample code: