iterate over all properties of a concept

I've declared some properties for a person object. Now I want to be able to iterate over the properties in textgen.

Code
for (node<Person> p : persons) {  
  for (<no type> <no name> : p.concept.getProperties()) { 
     // ...attach all properties to XML tree
  } 
} 
prettyPrint();


I know that I can access a property with 'p.propertyName', but I want my XML generation to be generic.
4 comments
Hi mschalk,

first, I recommend not to use the textgen aspects for your purpose. It is much easier and maintanable if you use the generator aspect. No matter which variant you choose, you can access the node's properties using the following code:

foreach propertyName in (p)/.getPropertyNames() { 
  // You can retrieve the properties from the node using the following get method. 
  (p)/.getProperty(propertyName); 
}
prettyPrint();

The slash ('/') after the (p) means "downcast to a lower semantic level". It is important that you choose the correct auto-completion entry. .
I hope that helps.

Regards,
LaAck
0
Hey!
Is there a possibility to get write access to property.. kind of reflection
0
Hi,

yes, you can write a property using the following syntax:
(node)/.setProperty("myProperty", "myValue");
prettyPrint();
However, this method is deprecated. So you may also use the following code snippet instead:
(node)/.setProperty(property/MyCoolConcept: myProperty/, "myValue");
prettyPrint();
The latter is the closest to the reflection mechanism in Java. You also can iterate over all available properties using the "getProperties()" methods of a concept or a "downcasted" node.

I hope this helps.

Regards,
LaAck
0

Please sign in to leave a comment.