I keep hitting the same minor problem, but dont have a really great
solution. So Im looking for ideas.
There are many instances where I want to force the developer ( me ) from a
readability and robustability point of view to choose from a list of
predefined choices when calling functions. Well, of course enums are good
for this, so I could have something like this. In which a webfrom textboxm
gets a css class attribute which equals the name of the enum member.
public enum messageType {fail=0,pass=1,warning=3}
public void message( string msgStr, messageType msgType )
{
myTextBox.Attributes.add("class",msgType.toString());
myTextBox.Text=msgStr;
}
// However. I would like to abstract the name used by the developer and the
actuall css class applied. Any suggestions on how to do this.
I thought instead of using an enum, I could use constant members but how
could I force the developer to enter the classtype with the constants in ?
Im sure someone has a groovy easy answer ! :)
Ignacio Machin ( .NET/ C# MVP ) - 09 Jan 2008 18:48 GMT
Hi,
I think that the enums are the best way to do what you want.
I do not understand what you mean with abstract the name.
You cuold create CSS that have a similar naming than the enum, for example
if the enum is Fail, the css could be FailCSS or something similar

Signature
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
>I keep hitting the same minor problem, but dont have a really great
>solution. So Im looking for ideas.
[quoted text clipped - 22 lines]
>
> Im sure someone has a groovy easy answer ! :)
Just Me - 09 Jan 2008 20:22 GMT
I dont think I can do what I had hoped. Thanks anyway. Enums will have to
do.
> Hi,
>
[quoted text clipped - 33 lines]
>>
>> Im sure someone has a groovy easy answer ! :)
Nicholas Paldino [.NET/C# MVP] - 09 Jan 2008 20:41 GMT
Are you looking to abstract it for display purposes, or because you want
a different list in Intellisense? If you want it for display purposes, you
could always create a list/map of other class instances which expose the
abstracted value (from any other data source you wish) as well as the enum
value. Then it is just a matter of a simple lookup.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>I keep hitting the same minor problem, but dont have a really great
>solution. So Im looking for ideas.
[quoted text clipped - 22 lines]
>
> Im sure someone has a groovy easy answer ! :)
Just Me - 09 Jan 2008 22:10 GMT
The purpose was to abstract the name the programmer would see when choosing
one of several enumerations, but the actual value would be different and
would represent the real css class to be applied to the control when the
page is rendered.
Its really a nice to have.
> Are you looking to abstract it for display purposes, or because you
> want a different list in Intellisense? If you want it for display
[quoted text clipped - 30 lines]
>>
>> Im sure someone has a groovy easy answer ! :)