I have an enum:
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
}
I would like to use this enum on the other side of a WCF service. As such, I need to serialize it!
I see the serializer generating the following:
/// <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,
}
Unfortunately, that’s no good. The following code works differently on either end.
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)
I looked around at some attribute decorators thinking I might find something useful: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx. This link shows how to change the serialization name, but does not state anything about the value.
Does this mean that I am not able to maintain my enum values using this serialization engine?
I ended up just adding a direct reference to the DLL containing the enum and avoided serialization altogether. Sorry, not a great answer, but I was unable to make this work.