michael
michael

Reputation: 15302

WSDL: How to create an enum with C# FlagsAttribute?

Basically, I created my WSDL and added a SimpleType with enum values: A, B, C. When I build my service with this wsdl I want the enum to be constructed with the FlagsAttribute, but how do I specify that in my wsdl?

I'm using svcutil.exe to generate my C# code.

Update: I am building my server-side code using svcutil.exe. I do so by calling: svcutil.exe "Foo.wsdl" "global.xsd". But, I'm unsure how to properly markup my wsdl/xsd tags so that the generated code comes out like so:

[Flags] //<-- How do you get this to become autogenerated?
public enum SomeEnum
{
    A,
    B,
    C
}

Upvotes: 0

Views: 1389

Answers (1)

Brad Christie
Brad Christie

Reputation: 101614

Enumeration Types in Data Contracts explains this pretty nicely. From their example:

[DataContract][Flags]
public enum CarFeatures
{
    None = 0,
    [EnumMember]
    AirConditioner = 1,
    [EnumMember]
    AutomaticTransmission = 2,
    [EnumMember]
    PowerDoors = 4,
    AlloyWheels = 8,
    DeluxePackage = AirConditioner | AutomaticTransmission | PowerDoors | AlloyWheels,
    [EnumMember]
    CDPlayer = 16,
    [EnumMember]
    TapePlayer = 32,
    MusicPackage = CDPlayer | TapePlayer,
    [EnumMember]
    Everything = DeluxePackage | MusicPackage
}

Unless I'm missing the point here.

Upvotes: 1

Related Questions