Primitive Array API Reference
The following APIs are introduced to support primitive arrays in Event Publication Subscription:
-
SetElement(element):Adds an element to a primitive array. The element can be a string or anotherPropertySet. For example:var ps = TheApplication().NewPropertySet(); ps.SetProperty("datatype", "jsonprimarray"); ps.SetElement("myname"); var childPS = TheApplication().NewPropertySet(); childPS.SetProperty("datatype", "jsonprimarray"); childPS.SetElement("childElement1"); childPS.SetElement("childElement2"); ps.SetElement(childPS);In this example, the primitive array contains:- The string
myname. - A nested
PropertySetthat contains the stringschildElement1andchildElement2.
- The string
IsNextElement():Returnstrueif another element is available in thePropertySet. Otherwise, returnsfalse. Use this method withGetNextElement().GetNextElement():Returns the next string element in thePropertySet. Use this method withIsNextElement().IsNextElementPropertySet():Returnstrueif the next element is aPropertySet. Use this method withGetNextElementAsPropertySet().GetNextElementAsPropertySet():Returns the nextPropertySetelement. Use this method withIsNextElementPropertySet(). For example:var ps = TheApplication().NewPropertySet(); var resPS = TheApplication().NewPropertySet(); ps.SetProperty("datatype", "jsonprimarray"); ps.SetElement("myname"); var childPS = TheApplication().NewPropertySet(); childPS.SetProperty("datatype", "jsonprimarray"); childPS.SetElement("childElement1"); childPS.SetElement("childElement2"); ps.SetElement(childPS); while (ps.IsNextElement()) { if (ps.IsNextElementPropertySet()) { resPS = ps.GetNextElementAsPropertySet(); // do something } else { var psStr = ps.GetNextElement(); // do something } }This example iterates through the
PropertySetand processes each element according to its type.RemoveElement(value):Removes the first primitive element that matches the specified value. For example:ps.RemoveElement("string"); ps.RemoveElement(32);Use this method for primitive values such as strings, numbers, and Boolean values. It does not remove nested
PropertySetelements by value.RemoveElementAt(index):Removes the element at the specified zero-based position.ps.RemoveElementAt(1);This method can remove either a primitive element or a PropertySet element.
ResetNextElementCount():Resets sequential element reading to the beginning.Use this method before reading the same elements again with sequential APIs such asIsNextElement()andGetNextElement(). For example:while (ps.IsNextElement()) { if (ps.IsNextElementPropertySet()) { resPS = ps.GetNextElementAsPropertySet(); // do something } else { var psStr = ps.GetNextElement(); // do something } } ps.ResetNextElementCount();GetNumberOfElements():Returns the total number of elements in thePropertySet. For example:var ps = TheApplication().NewPropertySet(); ps.SetProperty("datatype", "jsonprimarray"); ps.SetElement("myname"); var childPS = TheApplication().NewPropertySet(); childPS.SetProperty("datatype", "jsonprimarray"); childPS.SetElement("childElement1"); childPS.SetElement("childElement2"); ps.SetElement(childPS); var count = ps.GetNumberOfElements();In this example,
ps.GetNumberOfElements()returns2because thePropertySetcontains two elements: one string and one nestedPropertySet.IsElementPropertySetAt(index):Returnstrueif the element at the specified position is aPropertySet. For example:if (ps.IsElementPropertySetAt(3)) { // ... }Use this method before calling
GetElementAt()orGetElementAsPropertySetAt()when the element type is not known.GetElementAt(index):Returns the primitive element value at the specified zero-based position. For example:var value = ps.GetElementAt(0);Use this method only for primitive elements. If the element is a
PropertySet, useGetElementAsPropertySetAt()instead.GetElementAsPropertySetAt(index):Returns thePropertySetelement at the specified zero-based position.var child = ps.GetElementAsPropertySetAt(3);Use this method only when the element at that position is a
PropertySet. A common pattern is to callIsElementPropertySetAt(index)first.