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 / March 2005

Tip: Looking for answers? Try searching our database.

Using enums in parameters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stan - 15 Mar 2005 17:17 GMT
Suppose I have this enum

public class Flag
{
   Hazardous = 1,
   Protected = 2
}

and I have this webmethod:

[WebMethod]
public void SetFlag (Flag newFlag)
{
}

WSDL from this will be:

<s:element name="SetFlag">
- <s:complexType>
- <s:sequence>
   <s:element minOccurs="1" maxOccurs="1" name="newFlag" type="tns:Flag" />
   </s:sequence>

<s:simpleType name="Flag">
   - <s:restriction base="s:string">
             <s:enumeration value="Hazardous" />
              <s:enumeration value="Protected" />
     </s:restriction>
 </s:simpleType>

which means that client has to pass the enum name ("Hazardous").

However, I would like to pass value (1, 2) and not the name.

Of course, I can change the method to "int newFlag" but then a client can
pass anything..

Can I have enums but pass int?

Thanks,

-Stan
recoil@community.nospam - 15 Mar 2005 18:29 GMT
I think this defeats a major purpose of Enum from the client's and
developer's perspective. Nobody should care about the value of the
Enum. The Enum value for a specific enumeration could change 1000 times
and nobody should or  would care.
Is there a specific reason why one would want to do this?
Stan - 15 Mar 2005 19:37 GMT
I want the client to use enum, but pass its value and not the name. In case
of regular class with enum:

SetFlage (Flag.Hazardous)

Flag.Hazardous gets converted to its value

> I think this defeats a major purpose of Enum from the client's and
> developer's perspective. Nobody should care about the value of the
> Enum. The Enum value for a specific enumeration could change 1000 times
> and nobody should or  would care.
> Is there a specific reason why one would want to do this?

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.