Define the order of attributes a property of an entity is decorated with

Posts   
 
    
chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 23-Sep-2011 16:03:37   

Hi all,

using the newest version of the LLBLGen Pro 3.1 designer, i wonder how to define the order of attributes a property of an entity is decorated with. i experienced that they are automatically sorted alphabetical.

Because on the one hand it is important that I can define these attributes in the designer and on the other hand the MUST have a custom defined order.

My question: Where do I define the order of attributes decorating properties of entities?

Thanx in advance, best regards

Chris

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Sep-2011 20:14:06   

Mmm. There is no setting for that. In the template there is just a loop:

[Serializable]<[Foreach Attribute Entity]>
    <[Attribute]><[NextForeach]>

    public <[If UsePartialClasses]>partial <[EndIf]>class <[CurrentEntityName]>Entity : <[ If IsSubType ]><[ SuperTypeName ]>Entity<[ Else ]><[SettingValue Entity "EntityBaseClassName"]><[ EndIf ]><[Foreach AdditionalInterface]>, <[CurrentAdditionalInterface]><[NextForeach]><[ UserCodeRegion "AdditionalInterfaces" ]>
        // __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
        // __LLBLGENPRO_USER_CODE_REGION_END
        <[ EndUserCodeRegion ]> 
    {
...

As it is a Foreach token, you cannot specify an order on it. So, it you really need it, you could write a .lpt routine that emit the attributes and replace that loop with a call to your custom method. Let us know if you want to track into this workaround and need help.

Anyway, Could you please tell us Why it should be important to specify the order in which the attributes should be emitted? Maybe it could be considered in a feature request.

David Elizondo | LLBLGen Support Team
chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 26-Sep-2011 11:29:05   

Hi David,

the almost main reason, needing a defined order of attributes decorating a property (or type) from my point of view is, that if validating is done using the validation application block of the ms enterprise library 5.0, this might contain logical operators to combine validation attributes. What for example happens, might be something like:

AValAtt1 BValAtt2 CValAtt3 GValAtt4 HValAtt5 KCompose(or) LCompose(and)

Now, I ask myself what to when the following order is needed:

LCompose(and) AValAtt1 BValAtt2 CValAtt3 KCompose(or) GValAtt4 HValAtt5

and so on. Actually, I try to get information about how the "Composing" is implemented, but it might turn out, that the order is important.

I hope that gives you an insight of my needs, best regards

Chris

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 27-Sep-2011 09:49:38   

Attributes are read through reflection (as they're meta-data). The reflection api clearly states there's no 'order' in which things are obtained: a compiler can always re-order things, and it can even be the call to the reflection method is returning things in a different order each time.

Therefore there's no ordering defined for attributes, as it's not used by .net. I would be very surprised if the application block relied on attribute order as there IS no attribute order. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
chrissie
User
Posts: 84
Joined: 05-Oct-2010
# Posted on: 27-Sep-2011 10:16:09   

Hi Otis,

unfortunately, you are right. But I wonder on how to construct complex logical expressions with attributes without having an order. In the meantime, I am waiting for an answer from Avanade, the manufacture of the ms enterprise library.

Thank you for your answer, best regards

Chris