Show / Hide Table of Contents

    DwFunctionManager.AddGlobalFunction<TClass>() where TClass : class Method

    .NET Standard 2.x

    Adds global static functions which can be used in the DataStore.Evaluate function or in the computed columns with the DWCompute attribute.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public static void AddGlobalFunction<TClass>() where TClass : class;
    

    Type Parameters

    TClass

    The name of the class which contains one or more public static methods to add.

    Examples

    The following example demonstrates how to add one public static method from the class to be used as a DataWindow expression function.

    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.DwFunctionManagerExamples
    {
        public class AddGlobalFunctionExample
        {
            private readonly SchoolContext _context;
    
            public AddGlobalFunctionExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                DwFunctionManager.AddGlobalFunction<GlobleFunctions>();
    
                var ds = new DataStore("d_person", _context);
    
                ds.Retrieve();
    
                // Uses MyFunc method in DataWindow expression.
                bool b = ds.Evaluate<bool>("MyFunc(1)");
                Console.WriteLine("Result 1: {0}", b);
    
                b = ds.Evaluate<bool>("MyFunc(-1)");
                Console.WriteLine("Result 2: {0}", b);
    
                /*This code produces the following output:
                
                Result 1: True
                Result 2: False
                */
            }
        }
    
        // The class which contains public static methods.
        public class GlobleFunctions
        {
            public static bool MyFunc(int i)
            {
                return i > 0;
            }
        }
    }
    
    Back to top Generated by Appeon