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
| Name | Type | Description |
|---|---|---|
functionId | string | The unique identifier (GUID) of the dynamic function as a string. |
parameterValues | object[] | An array of argument values to pass to the function, in the order defined by the function. |
Exceptions
ArgumentException– iffunctionIdis null or empty.FunctionNotFoundException– iffunctionIdis 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
| Name | Type | Description |
|---|---|---|
functionName | string | The name of the dynamic function. |
parameterValues | object[] | An array of argument values to pass to the function. |
Exceptions
ArgumentException– iffunctionNameis null or empty.FunctionNotFoundException– iffunctionNameis 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);