Dynamic Function Execution

Part of the QSAppContext object. These methods execute a dynamic function by its identifier or name, passing a variable number of parameter values. They return the result as dynamic, meaning the actual type is determined at runtime. This is useful for calling generic or configurable functions where the signature is not known at compile time.

If the function execution fails on the server, an exception is thrown with the error message. If the function or identifier is missing or empty, an ArgumentException or FunctionNotFoundException is thrown.

ExecuteDynamicFunctionByIdAsync

public async Task<dynamic> ExecuteDynamicFunctionByIdAsync(string functionId, object[] parameterValues)

Parameters

NameTypeDescription
functionIdstringThe unique identifier (GUID) of the dynamic function as a string.
parameterValuesobject[]An array of argument values to pass to the function, in the order defined by the function.

Exceptions

  • ArgumentException – if functionId is null or empty.
  • FunctionNotFoundException – if functionId is empty string.
  • Exception – if the dynamic function execution returns an error.

Returns

A dynamic object representing the result of the function.

Example

// Function ID as a string GUID
string functionId = "b7f8c9e0-1234-4a5b-9c8d-1e2f3a4b5c6d";

// Parameter values (order matters)
object[] args = new object[] { 25, "VIP", true };

dynamic result = await QSAppContext.ExecuteDynamicFunctionByIdAsync(functionId, args);

Console.WriteLine(result);

ExecuteDynamicFunctionByNameAsync

public async Task<dynamic> ExecuteDynamicFunctionByNameAsync(string functionName, object[] parameterValues)

Parameters

NameTypeDescription
functionNamestringThe name of the dynamic function.
parameterValuesobject[]An array of argument values to pass to the function.

Exceptions

  • ArgumentException – if functionName is null or empty.
  • FunctionNotFoundException – if functionName is empty string.
  • Exception – if the dynamic function execution returns an error.

Returns

A dynamic object representing the result of the function.

Example

// Function name
string functionName = "CalculateCustomerDiscount";

// Parameter values
object[] args = new object[] { 1500.75M, "Gold" };

dynamic result = await QSAppContext.ExecuteDynamicFunctionByNameAsync(functionName, args);

Console.WriteLine(result);