我有一个枚举:
public enum ComponentType
{
None = -1,
Equipment = 0,
Cable = 2,
Port = 4,
Space = 8,
Site = 9,
Building = 10,
Floor = 11,
DataCenter = 12,
Area = 13,
Rack = 14,
Conduit = 16,
Person = 17,
Pit = 18
}
我想在 WCF 服务的另一端使用这个枚举。因此,我需要序列化它!
我看到序列化程序生成以下内容:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.website.com/api")]
public enum ComponentType {
/// <remarks/>
None,
/// <remarks/>
Equipment,
/// <remarks/>
Cable,
/// <remarks/>
Port,
/// <remarks/>
Space,
/// <remarks/>
Site,
/// <remarks/>
Building,
/// <remarks/>
Floor,
/// <remarks/>
DataCenter,
/// <remarks/>
Area,
/// <remarks/>
Rack,
/// <remarks/>
Conduit,
/// <remarks/>
Person,
/// <remarks/>
Pit,
}
不幸的是,这不好。以下代码在两端的工作方式不同。
int componentId = 123;
int flag = ComponentDao.GetFlagForComponentById(componentId);
ComponentType componentType = ((ComponentType)flag);
//componentType == ComponentType.None (client end of service)
//componentType == ComponentType.Equipment (server end of service)
我环顾了一些属性装饰器,认为我可能会发现一些有用的东西:http: //msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx。此链接显示如何更改序列化名称,但没有说明任何有关该值的内容。
这是否意味着我无法使用此序列化引擎维护我的枚举值?