Sdílet prostřednictvím


Adding an enumeration

If your document type uses an enumeration, you must add that enumeration to your project. To work with services, the enumeration must be serializable, and it must specify how to represent the enumeration in XML.

The enumeration must be in the same namespace as your document type. Typically, enumerations are added to the same file as the document type and document key classes.

The following code sample shows the LeadCategory enumeration. Notice how the enumeration includes the Serializable and DataContract attributes. In addition, each member has an XmlEnum and EnumMember attribute that specifies the value to use in XML.

[Serializable, DataContract]
public enum LeadCategory
{
    [XmlEnum("RealEstate")]
    [EnumMember(Value = "RealEstate")]
    RealEstate = 1,
    [XmlEnum("Wholesale")]
    [EnumMember(Value = "Wholesale")]
    Wholesale,
    [XmlEnum("Retail")]
    [EnumMember(Value = "Retail")]
    Retail,
    [XmlEnum("Contractor")]
    [EnumMember(Value = "Contractor")]
    Contractor,
    [XmlEnum("Educational")]
    [EnumMember(Value = "Educational")]
    Educational,
    [XmlEnum("Media")]
    [EnumMember(Value = "Media")]
    Media,
    [XmlEnum("Software")]
    [EnumMember(Value = "Software")]
    Software,
    [XmlEnum("Restaurant")]
    [EnumMember(Value = "Restaurant")]
    Restaurant
}