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 / ASP.NET / Web Services / April 2005

Tip: Looking for answers? Try searching our database.

Enum design question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stan - 15 Apr 2005 22:33 GMT
Suppose there is class with enum

public enum Color
{
   Red = 20,
   Black = 13
}

And suppose there is a method

public void SetColor (int id, Color c)
{

}

When web service proxy class is generated the value of the enums will be
lost:

public enum Color
{
   Red,
   Black
}

so that essentially Red = 1 and Black = 2

That creates some problems. For example if Red = 20 and Black = 13 are
database keys, it is impossible to update the database via web service,
since the passing values are different.

I can see two solutions for this:

1. Manually update enum in proxy class to
   public enum Color
   {
       Red = 20,
       Black = 13
   }

2. Change

public void SetColor (int id, Color c)

to

public void SetColor (int id, int c)

I don't really like either one.

Any thoughts or ideas?

Thanks,

-Stan
Salvador - 18 Apr 2005 10:01 GMT
Hi,

I found the same issue, so a way to solve it is specifying that is a flag
enum, use the following attribute

[Flags()]
public enum YourEnum

All your values will be respected,

hope this helps
Salva

> Suppose there is class with enum
>
[quoted text clipped - 50 lines]
>
> -Stan
Stan - 18 Apr 2005 13:54 GMT
Salva,

You probably meant [FlagsAttribute].

Unfortunately it will not work - enum values will be preserved in the proxy
class but the enum values will be 2 power n (2, 4, 8, 16,...) . I need the
values match my database id...

[FlagsAttribute]
public enum Color
{
    Red = 20,
    Black = 13
}

Will give me     Red = 2,   Black = 4

> Hi,
>
[quoted text clipped - 63 lines]
> >
> > -Stan

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.