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?