Bug Report T750705
Visible to All Users

Templates – The ForEach command is applied only once

created 6 years ago

Hi!

I have wrote next code template:
-----------------------------------------------
// auto declaration for «Paste»
«ForEach(public property in clipClass, #InitializeField#)»
-----------------------------------------------

and #InitializeField#
-----------------------------------------------
«?Get(itemName)» = «Field(value)»default(«?Get(itemType)»); // «?Get(itemType)» «?Get(itemName)»
-----------------------------------------------

And try to run it on class , for example EventArgs
I've try both - Class Name and variable of this class - all the times I've got empty result.

So, I have two questions:

  1. Is it possible to run this template for any class? I've try to run example with "this" instead of "public property" in first template and it's works like charm.
  2. 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?
Show previous comments (2)
DevExpress Support Team 6 years ago

    As the template is already expanded, CodeRush can't determine which type you typed after that. In this case, I suggest that you use the clipClass keyword in the ForEach command and copy the name of the necessary class before expanding the template.

    AG AG
    Aleksander Guszczin 6 years ago

      Can I use <<FinalTarget>> for this?
      Can you please explain how to use itemElement scope?

      DevExpress Support Team 6 years ago

        Yes, you can use the FinalTarget but in this case, you should use at least one Field (for example «FieldStart»«Link(Entity)»«FieldEnd»).

        The ItemElement can be used to iterate by the current element. See to the example:

        C#
        startTemplate «ForEach(namespace in file,#ProcessNamespace#) #ProcessNamespace# «ForEach(class in itemElement,#ProcessClass#) #ProcessClass# «ForEach(member in itemElement,#ProcessMember#) #ProcessMember# // «?Get(itemName)»

        I apologize for misleading you. It turns out there is the possibility of creating recursive templates.I have create a separate ticket to describe more detail on how to create recursive templates to help other users to easily find this information:
        Templates - How to create recursive templates with conditions

        Answers approved by DevExpress Support

        created 6 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          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.