I have a list of objects which belong to the custom defined class "Device", which I have serialized into an XML file. The class "Device" has a nested class called "Function".
<ArrayOfDevice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Device>
<Name>CellaTemp PA</Name>
<Type>DeviceX</Type>
<Station>2</Station>
<Function>
<Name>Function1</Name>
</Function>
</Device>
<Device>
<Name>EKU1 KR</Name>
<Type>DeviceY</Type>
<Station>1</Station>
<Function>
<Name>Function2</Name>
</Function>
Now I want to open this XML file "/.../DevicesXML" in a new C# solution and deserialize it into a list consisting of objects of the "Device" class.
How do I load the file correctly? Which commands and "using".namespaces do I need?
Do I have to define the classes in the new solution like in the original one?
The class "Device" has been defined as follows:
[Serializable()]
public class Device
{
public string Name { get; set; }
public string Type { get; set; }
public int Station { get; set; }
public Function func{ get; set; }
[Serializable()]
public class Function
{
public string Name { get; set; }
public Function() { }
public Function(string name = "No Name")
{
Name = name;
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Name", Name);
}
public Function(SerializationInfo info, StreamingContext context)
{
Name = (string)info.GetValue("Name", typeof(string));
}
}
public Device() { }
public Device(string name = "No Name", string type = "No type", int station = 0,
string sname="No Name", string sfeat="Nothing")
{
Name = name;
Type = type;
Station = station;
Func1= new Function(sname, sfeat);
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Name", Name);
info.AddValue("Type", Type);
info.AddValue("Station", Station);
info.AddValue("Func1", Func1);
}
public Device(SerializationInfo info, StreamingContext context)
{
Name = (string)info.GetValue("Name", typeof(string));
Type = (string)info.GetValue("Type", typeof(string));
Station = (int)info.GetValue("Station", typeof(double));
Func1= (Function)info.GetValue("Func1", typeof(Function));
}
}