UserCodeRegion Naming Schema

Posts   
 
    
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 30-Jan-2007 22:01:41   

Through trial and error I learned UserCodeRegion names carries significance. The name in the TDL must match the name in the commented code.

How can I index or rename the region in a foreach loop? I want to generate the FieldValidate code with all the field indexes listed. with user generated code within each case. Template Code Below

        /// <summary>Validates the new value for the <[CurrentEntityName]>Entity field.</summary>
        /// <param name="involvedEntity">The related <[CurrentEntityName]>Entity as an IEntityCore.</param>
        /// <param name="fieldIndex">Value of the <[CurrentEntityName]>FieldIndex enumerator.</param>
        /// <param name="value">proposed value for the <[CurrentEntityName]>Entity field.</param>
        /// <returns>True if valid. False if invalid.</returns>
        public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
        {
            bool toReturn = true;
            <[ UserCodeRegion "FieldBegin" ]>
            // __LLBLGENPRO_USER_CODE_REGION_START FieldBegin
            // __LLBLGENPRO_USER_CODE_REGION_END
            <[ EndUserCodeRegion ]>
            switch ((<[CurrentEntityName]>FieldIndex)fieldIndex)
            {<[ Foreach EntityField ]> 
                case <[CurrentEntityName]>FieldIndex.<[ EntityFieldName ]>:
                <[ UserCodeRegion "Field" ]>
                    // __LLBLGENPRO_USER_CODE_REGION_START Field
                    // __LLBLGENPRO_USER_CODE_REGION_END
                <[ EndUserCodeRegion ]>
                    break;<[ NextForeach ]>
                default:
                    toReturn = false; 
            }
            
            return toReturn;
        }

the problem is Field is repeated for every section. the only code preserved is the first Field block. So if the first field has no validion all fields have no validation. if the first field does have code then all fields will contain the same validation code.

I tried using the EntityFieldName for the UserCodeRegion, but that produced incorrect syntax.

can I dynamically set the name of the UserCodeRegion using TDL? If not TDL can I use LogicC#? Is there a reference manual on LogicC# syntax?

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 31-Jan-2007 06:56:29   

I don't think you can inset user code region in the generated code. In other words, they won't be useful, as the code generation process looks for user code regions in specific places.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 31-Jan-2007 09:48:47   

As a matter of fact, you can! simple_smile It's true that the name in the template has to match the name in the existing code file. You can set the name dynamically though. See the second UserCodeRegion syntaxis in teh SDK docs:


<[UserCodeRegion StringValueName Pattern]>
comment
<[EndUserCodeRegion]>

The user code regions are meant to add code after code generation, and if you're emitting several of them in a loop, be sure the begin and end tags are inside the loop (it looks like your start tag is outside the loop)

Frans Bouma | Lead developer LLBLGen Pro
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 31-Jan-2007 15:10:57   

I'm really close, but I can't figure out what the Pattern should be. Here is the portion of my template that is causing problems.

<[ Foreach EntityField ]> 
case <[CurrentEntityName]>FieldIndex.<[ EntityFieldName ]>:
    <[ UserCodeRegion  EntityFieldName  "_"  ]>
    // __LLBLGENPRO_USER_CODE_REGION_START <[ EntityFieldName ]> 
    // __LLBLGENPRO_USER_CODE_REGION_END
    <[ EndUserCodeRegion ]>
    break;
<[ NextForeach ]>

Reviewing the SDK docs EntityFieldName is in the right place. I set _"" as my pattern only because this doesn't create bad output. I tried replacing _"" with "", " ", _UserCodeRegionName _. These variations cause invalid output.

The docs state

"pattern" is the name pattern to use for the region. The string can be a solid name, or can be a string which can have a macro: ($VALUE). The macro ($VALUE) is replaced with the name value specified using the argument. When using this variant of UserCodeRegion, use UserCodeRegionName in the marker section for proper name emitting.

I'm not quite sure what this means. I don't want to run a macro against the name, and I don't think I have a pattern to emit either. In the last sentence the docs reference UserCodeRegionName. What is this? I searched the SDK and this is the only reference. I think if I knew what this was I would have a better understanding of my problem.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 31-Jan-2007 15:31:07   

after some forum searching and testing I found the correct code to execute.

<[ Foreach EntityField ]> 
case <[CurrentEntityName]>FieldIndex.<[ EntityFieldName ]>:
<[UserCodeRegion EntityFieldName "($VALUE)"]>
       // __LLBLGENPRO_USER_CODE_REGION_START <[ UserCodeRegionName ]>
       // __LLBLGENPRO_USER_CODE_REGION_END
<[EndUserCodeRegion]>
break;
<[ NextForeach ]>

The helpful posts: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4048 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4005

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 31-Jan-2007 16:13:33   

Thanks for the feedback.