S
slamb
Hi all,
Does anyone know of a way to deserialize xml data that has an element
that represents an enum value but is actually an int?
I know I can use [XmlEnum(Name="23")] to tag enum values, that works
but is too messy. I have many enums and tagging all values would not
be good.
xml data
<Top>
<Element>23</Element>
</Top>
c# code
public enum SomeEnumType
{
Value1 = 23,
Value2 = 15
}
public class Top
{
SomeEnumType Element;
}
SomeEnumType Deserialize(Stream stream)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Top));
object obj = xmlSerializer.Deserialize(stream);
Top top = obj as Top;
if (top == null)
throw new SomeException();
return top.Element;
}
Does anyone know of a way to deserialize xml data that has an element
that represents an enum value but is actually an int?
I know I can use [XmlEnum(Name="23")] to tag enum values, that works
but is too messy. I have many enums and tagging all values would not
be good.
xml data
<Top>
<Element>23</Element>
</Top>
c# code
public enum SomeEnumType
{
Value1 = 23,
Value2 = 15
}
public class Top
{
SomeEnumType Element;
}
SomeEnumType Deserialize(Stream stream)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Top));
object obj = xmlSerializer.Deserialize(stream);
Top top = obj as Top;
if (top == null)
throw new SomeException();
return top.Element;
}