en en en en en en en en en en en cs en en en en en en en en en en en en en en en en en en en en cs en en en en en en en en en en en en en en en en en pt en en en en en en en en sv fr fr en en en en cs en en en en en
There are some scenarios from which you may build a dynamic structure using your rules. In order to do that, you need to:
Use native support for complex object hierarchy
Use new function to create an instance
Use Var to build up your structure
In the example below, we used Procedure logic, but the concept is the same and you can use any other type of logic when required.
Using an expression for array and dictionary allows the building of complex values (objects), as shown below:
In the expression above, using { and } defines a set of key/value. And [ and ] defines collection of objects and values.
For more details, check Native complex value.
FlexRule’s (version 6+) dynamic object automatically creates a nested structure, as new properties are assigned using the |key.
The sample model below creates a complex object using |key monad and assigns it to the obj parameter.
Line 8 creates a property named Father and a nested property called Name which has a value of Sam. This way, you don’t need to create and manage nested properties manually.
In this approach, |asJson monad is used to create a complex dynamic object using JSON representation. Let’s assume we have the JSON below:
{ Name: 'John', Age: 39, Father: { Name: 'Sam' } }
And the following model uses the |asJson monad to create a complex object and assign it to the obj parameter.
Hashtable can be used to create your hierarchical dynamic structure
Dictionary can be used to create your hierarchical dynamic structure:
When you want your application to get a dynamic object rather than a dictionary, then you can use ExpandoObject
The difference between these two approaches is that the ‘ExpandoObject’ expression is more intuitive, but to assign a new member in ‘Dictionary or Hashtable Object’, the Add method should be used.