Skip to main content
A newer version of this page is available. .

CustomFunctions Class

Contains static methods to register a custom function for the End-User Report Designer‘s Expression Editor.

Namespace: DevExpress.XtraReports.Expressions

Assembly: DevExpress.XtraReports.v20.2.dll

Declaration

public static class CustomFunctions

Remarks

The CustomFunctions class allows you to register a custom function that users can utilize in the Expression Editor for expression bindings and calculated fields.

A custom function implements the DevExpress.XtraReports.Expressions.ReportCustomFunctionOperatorBase interface.

The following code defines a custom function:

using DevExpress.XtraReports.Expressions;
using System;
// ...
    public class CustomFormatFunction : ReportCustomFunctionOperatorBase
    {
        public override string FunctionCategory 
            => "String";
        public override string Description 
            => "CustomFormatFunction(string format, object arg0)" +
            "\r\nConverts an arg0 value to a string based on a specified format";
        public override bool IsValidOperandCount(int count) 
            => count == 2;
        public override bool IsValidOperandType(int operandIndex, int operandCount, Type type) 
            => true;
        public override int MaxOperandCount
            => 2;
        public override int MinOperandCount
            => 2;
        public override object Evaluate(params object[] operands)
        {
            string res = String.Format(operands[0].ToString(), operands[1]);
            return res;
        }
        public override string Name 
            => "CustomFormatFunction";
        public override Type ResultType(params Type[] operands)
        {
            return typeof(string);
        }
    }

Call the static CustomFunctions.Register method to register a custom function. Pass the custom function class instance as a parameter. To unregister a custom function, use the static CustomFunctions.Unregister method.

The following code registers a custom function for use in the End-User Designer:

private void Form1_Load(object sender, EventArgs e)
{
    DevExpress.XtraReports.Expressions.CustomFunctions.Register(new NewLineConstant());
    DevExpress.XtraReports.Expressions.CustomFunctions.Register(new CustomFormatFunction());
    reportDesigner1.OpenReport("Reports\\XtraReport1.repx");
}

Inheritance

Object
CustomFunctions
See Also