EntityFactory & FieldIndex

Posts   
 
    
simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 14-Aug-2007 18:21:56   

I've created a new OrderEntityFactory to add loads of calculated fields onto the entity. How do I manage the OrderFieldIndex enum so that I don't end up with having to hardcode field indexes?

public partial class OrderEntity public string Amount object value = this.Fields[this.Fields.Count - 1].CurrentValue;

..... public override IEntityFields2 CreateFields() IEntityField2 scalarField = new EntityField2("Amount", new MyExpression(OrderFields.Stuff));

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 14-Aug-2007 19:44:31   

I've created a new OrderEntityFactory to add loads of calculated fields onto the entity. How do I manage the OrderFieldIndex enum so that I don't end up with having to hardcode field indexes?

public partial class OrderEntity public string Amount object value = this.Fields[this.Fields.Count - 1].CurrentValue;

..... public override IEntityFields2 CreateFields() IEntityField2 scalarField = new EntityField2("Amount", new MyExpression(OrderFields.Stuff));

Let me see if I get what you meant: you want to extend the OrderFieldIndex enum so you can refer to your computed fields through it? (ie: OrderFieldIndex.[MyComputedField]) ? If So, I think is more suitable if you just refer to it by name (ie: yourOrderEntityInstance.Fields["amount"])

simon831
User
Posts: 152
Joined: 19-Jan-2006
# Posted on: 14-Aug-2007 20:44:25   

Ideally what I want is to either have OrderFieldIndex regenerate itself or store the 'new' entries in a partial class or use something like a region:

// __LLBLGENPRO_USER_CODE_REGION_START xxxx // __LLBLGENPRO_USER_CODE_REGION_END

What I seem to be doing is manually maintaining a list and trying to stop the developers from using the normal FieldIndex enum....

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 15-Aug-2007 05:06:59   

simon831 wrote:

Ideally what I want is to either have OrderFieldIndex regenerate itself or store the 'new' entries in a partial class or use something like a region:

// __LLBLGENPRO_USER_CODE_REGION_START xxxx // __LLBLGENPRO_USER_CODE_REGION_END

What I seem to be doing is manually maintaining a list and trying to stop the developers from using the normal FieldIndex enum....

Unless you can persuade Frans to replace all the enums with static classes and public consts sunglasses , I don't think you can directly extend the enum. However, there is a helpful AmountOfFields property so you can always automatically start your numbering after that.

For a TypedList, I added a couple of extra constants in the partial class like this:-


public const int FollowUpMessagesFieldIndex = (int) ShipDFNTypedListFieldIndex.AmountOfFields;
public const int HasPriorityMessagesFieldIndex = FollowUpMessagesFieldIndex + 1;

They could also go in your custom factory so you can easier tell the difference between normal and extended fields.

Cheers Simon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 15-Aug-2007 11:57:19   

Unfortunately, you can't inherit from an enum, so indeed consts is all you have.

Frans Bouma | Lead developer LLBLGen Pro