Вы должны сделать это:
using System.Xml.Serialization;
[Serializable]
public enum NameEnum
{
[XmlEnum(Name = "a")]
a,
[XmlEnum(Name = "b")]
b,
[XmlEnum(Name = "c")]
c
}
Рабочий пример, добавить в консольное приложение:
class Program
{
static void Main(string[] args)
{
AClass c = new AClass();
c.Name = NameEnum.c;
c.Value = 2;
using (MemoryStream ms = new MemoryStream())
{
XmlSerializer s = new XmlSerializer(typeof(AClass));
s.Serialize(ms, c);
File.WriteAllBytes(@"c:\test\serializeEnum.xml", ms.ToArray());
}
using (MemoryStream ms2 = new MemoryStream(File.ReadAllBytes(@"c:\test\serializeEnum.xml")))
{
XmlSerializer xs = new XmlSerializer(typeof(AClass));
AClass t = (AClass)xs.Deserialize(ms2);
Console.WriteLine(t.Name.ToString());
Console.WriteLine(t.Value.ToString());
Console.ReadLine();
}
}
}
[Serializable]
public enum NameEnum
{
[XmlEnum(Name = "a")]
a,
[XmlEnum(Name = "b")]
b,
[XmlEnum(Name = "c")]
c
}
[Serializable]
public class AClass
{
public NameEnum Name { get; set; }
public int Value { get; set; }
}