Back to Devexpress

ReportCustomFunctionOperatorBase Class

xtrareports-devexpress-dot-xtrareports-dot-expressions-0b78a14b.md

latest4.8 KB
Original Source

ReportCustomFunctionOperatorBase Class

A base class for custom functions in the Expression Editor.

Namespace : DevExpress.XtraReports.Expressions

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public abstract class ReportCustomFunctionOperatorBase :
    IReportCustomFunctionOperator,
    ICustomFunctionOperatorBrowsable,
    ICustomFunctionOperator,
    ICustomFunctionCategory
vb
Public MustInherit Class ReportCustomFunctionOperatorBase
    Implements IReportCustomFunctionOperator,
               ICustomFunctionOperatorBrowsable,
               ICustomFunctionOperator,
               ICustomFunctionCategory

Remarks

To create a custom function, create an object that descends from the ReportCustomFunctionOperatorBase abstract class.

The following code defines a custom function (NewLineConstant) that inserts a new line symbol:

csharp
using DevExpress.XtraReports.Expressions;
using System;
namespace CustomFunctionForExpressionEditorExample
{
    public class NewLineConstant : ReportCustomFunctionOperatorBase
    {
        public override string FunctionCategory 
            => "String";
        public override string Description 
            => "NewLineConstant()\r\nInserts a new line.";
        public override bool IsValidOperandCount(int count) 
            => count == 0;
        public override bool IsValidOperandType(int operandIndex, int operandCount, Type type)
            => true;
        public override int MaxOperandCount => 0;
        public override int MinOperandCount
            => -1;
        public override object Evaluate(params object[] operands)
        {
            return Environment.NewLine;
        }
        public override string Name
            => "NewLineConstant";
        public override Type ResultType(params Type[] operands)
        {
            return typeof(string);
        }
    }
}
vb
#Region "#usings"
Imports DevExpress.XtraReports.Expressions
Imports System
#End Region
Namespace CustomFunctionForExpressionEditorExample
    #Region "#NewLineConstant"
    Public Class NewLineConstant
        Inherits ReportCustomFunctionOperatorBase

        Public Overrides ReadOnly Property FunctionCategory() As String
            Get
                Return "String"
            End Get
        End Property
        Public Overrides ReadOnly Property Description() As String
            Get
                Return "NewLineConstant()" & ControlChars.CrLf & "Inserts a new line."
            End Get
        End Property
        Public Overrides Function IsValidOperandCount(ByVal count As Integer) As Boolean
            Return count = 0
        End Function
        Public Overrides Function IsValidOperandType(ByVal operandIndex As Integer,
                                                     ByVal operandCount As Integer,
                                                     ByVal type As Type) As Boolean
            Return True
        End Function
        Public Overrides ReadOnly Property MaxOperandCount() As Integer
            Get
                Return 0
            End Get
        End Property
        Public Overrides ReadOnly Property MinOperandCount() As Integer
            Get
                Return -1
            End Get
        End Property
        Public Overrides Function Evaluate(ParamArray ByVal operands() As Object) As Object
            Return Environment.NewLine
        End Function
        Public Overrides ReadOnly Property Name() As String
            Get
                Return "NewLineConstant"
            End Get
        End Property
        Public Overrides Function ResultType(ParamArray ByVal operands() As Type) As Type
            Return GetType(String)
        End Function
    End Class
    #End Region
End Namespace

Call the static CustomFunctions.Register method at application startup to register a custom function.

Inheritance

Object ReportCustomFunctionOperatorBase

See Also

ReportCustomFunctionOperatorBase Members

DevExpress.XtraReports.Expressions Namespace