Access .NET indexed properties dynamically
- Last Updated: June 19, 2019
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Syntax
You can access or set .NET indexed properties
dynamically using the DYNAMIC-PROPERTY function
by providing a character expression for the property name, along
with an object reference, the THIS-OBJECT system
reference, or a class type. At runtime, the AVM determines the actual
type, resolves the property name expression, validates the property
name against the actual type, and validates and performs the assignment.
This
is the syntax of the DYNAMIC-PROPERTY function:
|
This is the syntax of the DYNAMIC-PROPERTY statement:
|
Element descriptions for these syntax diagrams follow:
- return-value
- Specifies a data element
that is assigned the value returned when you execute the property's
GETaccessor. The appropriateCASTor ABL data type conversion function is applied to convert the property's value to the data type of return-value. - object-reference
- Specifies a reference to a .NET class instance that exposes the specified property as an instance member. The compiler allows object-reference to be declared as any object type. At runtime, the object type must resolve to the type that exposes the property.
- class-type-name
- Specifies
the name of a .NET class type that defines the specified property as
a static member. This is a
CHARACTERexpression that the AVM evaluates to the type name of a class at runtime. It must be the name of a class: interfaces are not valid. - property-name
- Specifies
a
CHARACTERexpression that evaluates to the property's name at runtime. For non-dynamic access, you can refer to a .NET indexed property without using the property name. In dynamic access, however, you must use the property name. - index
- Specifies
an index of the specified element. For a .NET indexed property, index is
an expression for the specified element. At compile time,
indexcan be any data type that ABL supports for indexers. However, at runtime, it must resolve to a data type appropriate to the property type. - new-value
- The
value of any data type that can be assigned to the property.
Note: The value of new-value cannot be converted to the property's type.
ABL also provides the GetPropertyValue( ) and SetPropertyValue( ) methods
with functionality similar to the DYNAMIC-PROPERTY function
and statement, respectively. Use the GetPropertyValue( ) and SetPropertyValue( ) methods
to access and set a property value at runtime, when you do not know
the property's name or type at compile time. There is a difference
between GetPropertyValue( ) or SetPropertyValue( ) and DYNAMIC-PROPERTY—using GetPropertyValue( ) or SetPropertyValue( )requires
an instance of Progress.Lang.Class in addition
to the object reference when accessing instance properties.
Conversions
between the property type and the source type of a SET or
the target type of a GET succeed as long as the
conversion between the data type of the source and the data type
of the target of the assignment is supported. The AVM does the required
conversions automatically as if there were a CAST or
an ABL data type conversion function such as STRING or INTEGER present.