473,474 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Enum design question

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
Nov 23 '05 #1
2 2644
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
"Stan" wrote:
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

Nov 23 '05 #2
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
"Salvador" <Sa******@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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
"Stan" wrote:
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

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't...
6
by: James Brown | last post by:
Hi, I have the following enum declared: enum TOKEN { TOK_ID = 1000, TOK_NUMBER, TOK_STRING, /*lots more here*/ }; What I am trying to do is _also_ represent ASCII values 0-127 as TOKENs...
6
by: Donal McWeeney | last post by:
Hi, I have a quick question on a design approach using enums - based on the model of something like the HtmlTextWriterTag enum. I presume that what the text writer does is use the Enum.GetName...
3
by: Tyler | last post by:
The MSDN help on the enum keyword for the C# language indicates that it is possible to give an enumeration a base-type other than int. In my case, I have chosen to give it a base type of uint. ...
5
by: Andrea Williams | last post by:
I'm working with C# and I'm setting up some ENUM's I have a data and Business layer. I'm declaring a common enum for the Data Layer. The UI layer references the Bus layer and the bus layer...
6
by: Ryan Taylor | last post by:
Hello. I have a quick and "simple" question that will probably boil down to opinion more than anything else. I need a FieldType property for a class I am writing. As such an Enum would be the...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
4
by: Jure Bogataj | last post by:
Hi all! I have two enumerations: public enum MyEnum1 and public enum MyEnum2 I want to create function that accepts parameter as member of either enumeration. Is this at all possible?
2
by: Daniel Jeffrey | last post by:
Hello. Can anyone help me please. I have created an Enumeration, and I loop through it, it all works ok, except the first item returns 2 times. Code is below. When called I Get "Text Edit" 2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.