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