Official Content

Defines generic and flexible data structures within the context of an External Object.

Description

Types can be dynamically adapted to different data types without requiring specific definitions for each case. That is, the same Type can be used with different data types, which adds a layer of flexibility and reusability to the design of External Objects.

Each Type in an External Object has properties such as Property NameValid TypesAllow Collection, and Default Type.

To define a Types node, set the Native Object value in the Type property in External Object.

Sample

Suppose you are developing an application in GeneXus and you need to implement a generic dictionary that can dynamically adapt to different types of data. To achieve this, you use External Objects.

First, create an External Object manually from the New object dialog, called GenericDictionary, and set the value Native Object in the Type Property

Next, define the following elements:

  • Types: Create a generic type called TypeKey for the keys and another generic type called TypeValue for the values.
  • Properties: Add properties called Keys and Values of type TypeKey and TypeValue, respectively, that store the dictionary elements. 
  • Methods: Implement the methods to add, delete, and get items from the dictionary.
  • Events: It is not necessary to define any.

The GenericDictionary structure is as follows:

GenericDictionary_png

Note that you can reference TypeKey and TypeValue within the same External Object.

The values set for the TypeKey properties are shown in the following image:

GenericDictionary1_png

After saving the created External Object, you can define a variable of the GenericDictionary data type. For example, in a Procedure object define a &Data variable of GenericDictionary type.

Make sure to define Key Type and Value Type as required:

GenericDictionary3_png

Once you have defined the &Data variable, you can access its properties and methods by adding a period:

GenericDictionary2_png

Note: Keep in mind that collections of an External Object with defined Types are not allowed.

Availability

This functionality is available as Beta since GeneXus 18 Upgrade 10.

   

Last update: November 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant