Ticket T750909
Visible to All Users

Templates - How to create recursive templates with conditions

created 6 years ago

[DevExpress Support Team: CLONED FROM T750705: Templates - The ForEach command can be applied only once for some reason]
Hi!

  1. Is if possible to iterate recursively class properties in foreach statement and run template for Icollection public properties? I need some reflection functionality inside template - if yes - can you please show an example how to do this?

Answers approved by DevExpress Support

created 6 years ago

You should create few templates and one of them will be the entry point.

For example, the template which will be iteratde by properties in the class from the clipboard:

C#
Name: start Body: «ForEach(property in clipClass,#ProcessProperty#)»

The ProcessProperty template with additional context which will be called only if the type of the current property implements the ICollection interface:

C#
Name: #PropessProperty# Body: «:#ProcessDefault#» «ForEach(property in «?Get(itemType)»,#ProcessProperty#)»«FieldStart»«Link()»«FieldEnd» Context: [TypeImplements(«?Get(itemType)»,System.Collections.ICollection)]

The ProcessProperty template without any contexts which will be called if the condition for the previous template is not satisfied:

C#
Name: #ProcessProperty# Body: «:#ProcessDefault#»

And the last template which will be called to show information about current property:

C#
Name: #ProcessDefault# Body: «?Get(itemName)» = default(«Field(«?Get(itemType)»)»); // «?Get(itemType)» «?Get(itemName)»

I hope this information will helpful for you.

    Comments (1)
    DevExpress Support Team 6 years ago

      Hello Aleksander,

      Just wanted to check whether or not the solution we provided meets your requirements.  Did you have a chance to try the template I provided?  Does this approach work as expected in your scenario?

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.