Custom function to read from business object

Stimulsoft Reports.NET discussion
Post Reply
Tobias
Posts: 105
Joined: Mon Nov 24, 2008 8:44 am

Custom function to read from business object

Post by Tobias »

Right now I'm doing this:

Code: Select all

public static class CustomFunctions
{
    public static string? GetValueByKey(StiBusinessObject businessObject, string key)
    {
        businessObject.Connect();
        try
        {
            if (businessObject.BusinessObjectValue is not IDictionary<string, string> dictionary) return null;
            return dictionary.TryGetValue(key, out var value) ? value : null;
        }
        finally
        {
            businessObject.Disconnect();
        }
    }

    public static void Register()
    {
        StiFunctions.AddFunction(
            category: "HELPERS",
            functionName: nameof(CustomFunctions.GetValueByKey),
            description: "Returns value by key from dictionary.",
            typeOfFunction: typeof(CustomFunctions),
            returnType: typeof(string),
            returnDescription: "The matching value or null",
            argumentTypes: [typeof(StiBusinessObject), typeof(string)],
            argumentNames: ["Dictionary", "Key"]);
    }
}
But I would like to chang this to a simpler "string GetDescription(string key)" and have the businessObject somehow hard-wired / looked up in the custom function.

Is there a way to do this?
Lech Kulikowski
Posts: 7424
Joined: Tue Mar 20, 2018 5:34 am

Re: Custom function to read from business object

Post by Lech Kulikowski »

Hello,

Unfortunately, it is not possible via a custom function.

In the compilation mode, you can add it in the Code tab.

Thank you.
Post Reply