Hi Polo,
I don't know what stops your class from working. Does it have any
constructors? If so it must have a default constructor too. Try to be more
explicit when defining serialization options.
Here is a working sample of a serializable class with two enum values:
using System;
using System.IO;
using System.Xml.Serialization;
using System.Windows.Forms;
namespace Serialize
{
public enum Values{A,B}
public enum ValuesB{C,D}
[XmlRoot("TryIt")]
public class Test
{
private Values v1;
private ValuesB v2;
[XmlAttribute("ValueOne")]
public Values V1
{
get{return v1;}
set{v1=value;}
}
[XmlAttribute("ValueTwo")]
public ValuesB V2
{
get{return v2;}
set{v2=value;}
}
}
public class MainClass
{
public static void Main()
{
Test t=new Test();
t.V1=Values.A;
t.V2=ValuesB.C;
XmlSerializer serializer=new XmlSerializer(typeof(Test));
FileStream fs=new FileStream(string.Format("{0}/output.xml",
Application.StartupPath),
FileMode.Create, FileAccess.Write);
try
{
serializer.Serialize(fs,t);
}
finally
{
fs.Close();
}
}
}
}
This self contained little app will generate a file that contains this:
<?xml version="1.0"?>
<TryIt xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ValueOne="A"
ValueTwo="C" />
/Hugo
On Tue, 16 Nov 2004 10:05:32 +0100, Polo wrote:
Hi,
I have two public enums types each defined in a class (PolarDiagram and
KDiagram) in a namespace (RTech.Graphic)
I try to serialize this class with XmlSerializer without success
A suggestion ?
Thank's
Polo
[Serializable()]
public class Template
{
[XmlAttribute()]
public RTech.Graphic.PolarDiagram.ViewMode View =
RTech.Graphic.PolarDiagram.ViewMode.HalfMode;
[XmlAttribute()]
public RTech.Graphic.KDiagram.ViewMode View2 =
RTech.Graphic.KDiagram.ViewMode.TwoSide;
}