all groups > dotnet web services > april 2005 >
You're in the

dotnet web services

group:

Enum design question


Enum design question Stan
4/15/2005 5:33:05 PM
dotnet web services: 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

RE: Enum design question Salvador
4/18/2005 2:01:02 AM
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


[quoted text, click to view]
Re: Enum design question Stan
4/18/2005 8:54:43 AM
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


[quoted text, click to view]

AddThis Social Bookmark Button