Skip to main content

ICustomFunctionOperatorBrowsable Interface

Contains descriptive information about a custom function for use in the Expression editor (category, description, number of parameters).

Namespace: DevExpress.Data.Filtering

Assembly: DevExpress.Data.v23.2.dll

NuGet Package: DevExpress.Data

Declaration

public interface ICustomFunctionOperatorBrowsable :
    ICustomFunctionOperator

Remarks

Implement this interface to make your custom function available for end users in Expression Editors. If you want to use your custom function in CriteriaOperator-based criteria on the server side (to query a database), implement the ICustomFunctionOperatorFormattable interface.

Example

The following code implements the StdDev custom function intended only for SQL queries in Query Builder. The Format method modifies the query string.

When this function is used in an expression, the Evaluate method throws an exception.

using System;
using System.Collections.Generic;
using DevExpress.Data.Filtering;


namespace SelectQueryWindowsFormsApplication {
    public sealed class StDevFunction : ICustomFunctionOperatorBrowsable, ICustomFunctionOperatorFormattable {
        const string name = "StDev";
        public static void Register() {
            CriteriaOperator.RegisterCustomFunction(new StDevFunction());
        }
        public static void Unregister() {
            CriteriaOperator.UnregisterCustomFunction(name);
        }
        public static readonly HashSet<Type> ValidOperandTypes = new HashSet<Type> {
            typeof(sbyte),
            typeof(byte),
            typeof(short),
            typeof(ushort),
            typeof(int),
            typeof(uint),
            typeof(long),
            typeof(ulong),
            typeof(decimal),
            typeof(double),
            typeof(float)
        };

        #region ICustomFunctionOperator
        public Type ResultType(params Type[] operands) {
            return typeof(double);
        }
        public object Evaluate(params object[] operands) {
            throw new NotSupportedException();
        }
        public string Name { get { return name; } }
        #endregion

        #region ICustomFunctionOperatorBrowsable
        public FunctionCategory Category { get { return FunctionCategory.Math; } }
        public string Description { get { return "Standard deviation function"; } }
        public bool IsValidOperandCount(int count) {
            return count == 1;
        }
        public bool IsValidOperandType(int operandIndex, int operandCount, Type type) {
            return ValidOperandTypes.Contains(type);
        }
        public int MaxOperandCount { get { return 1; } }
        public int MinOperandCount { get { return 1; } }
        #endregion

        #region ICustomFunctionOperatorFormattable
        public string Format(Type providerType, params string[] operands) {
            return string.Format("stdev({0})", operands[0]);
        }
        #endregion
    }
}

View Example: Reporting for WinForms - Implement a Custom Function for Use in a Query Expression

See Also