Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Enums Type Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Just Me - 09 Jan 2008 18:40 GMT
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 ! :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.