Enums or NameValueList

Enums or NameValueList

Old forum URL: forums.lhotka.net/forums/t/3247.aspx


lprada posted on Sunday, July 22, 2007

I have to create a Criteria to search by a Invoice Status, what is the best porcedure, to have a enum as a parameter of the criteria or have a NameValueList and an int as the parameter?

skagen00 replied on Monday, July 23, 2007

I prefer using something like a NameValueList. You have the flexibility of being able to show the descriptions associated with the values (enums you can't have spaces/etc). Also, you can have static properties on your NameValueList to represent any "magic numbers" you'd like to represent. (Such as InvoiceStatus.Paid).

Also, I don't know if it applies to you but if you have the ability for users to define their own status codes (over time) an enumeration wouldn't work well.

Good luck,

Chris

 

lprada replied on Tuesday, July 24, 2007

Thanks for the quickly response, now I have two Questions:

1) Adding the Static properties means that If I have to add a value to the list I have to added the property too, I use to have this discutions with my fellow  classmate and we never have a better idea, is any?

2) Add the property to the NVList or create a new class?

 

RockfordLhotka replied on Wednesday, July 25, 2007

Or potentially use the best of both worlds

http://forums.lhotka.net/forums/post/16045.aspx

skagen00 replied on Wednesday, July 25, 2007

This is nice if these two things aren't important:

1) client defined codes on top of enumerated "magic number" system codes

2) more than one word or description separate (culture variants or spaces in the description, etc) from that of the enum's name. Such as Dark Red instead of DarkRed.  (Of course, one could use certain rules to add proper spaces to the enum names).

lprada replied on Wednesday, July 25, 2007

I like the Rocky solution but I need translation of text, so what can I do, is there a way to ue reflexion to search into Properties.Resources?

RockfordLhotka replied on Wednesday, July 25, 2007

You probably shouldn’t use an enum if you need translation. You’d be better off making this list drive off a database table in that case.

 

Rocky

 

 

From: lprada [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 25, 2007 9:55 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Enums or NameValueList

 

I like the Rocky solution but I need translation of text, so what can I do, is there a way to ue reflexion to search into Properties.Resources?

Copyright (c) Marimer LLC