I have a classe which derives from sorted set and has some members:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Application.Model
{
[Serializable]
public class Trajectory : SortedSet<PolarPosition>
{
public delegate void DataChangedEventHandler();
public event DataChangedEventHandler DataChanged = delegate { };
public Trajectory()
: base(new PolarPositionComparer())
{
this.Name = "new one";
}
public Trajectory(IComparer<PolarPosition> comparer)
: base(comparer)
{
this.Name = "new compared one";
}
public Trajectory(IEnumerable<PolarPosition> listOfPoints)
: base(listOfPoints, new PolarPositionComparer())
{
this.Name = "new listed one";
}
public Trajectory(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
public string Name { get; set; }
public CoordinateSystemEnum UsedCoordinateSystem { get; set; }
public new bool Add(PolarPosition point)
{
DataChanged();
return base.Add(point);
}
}
}
With this enum:
[Serializable]
public enum CoordinateSystemEnum
{
Polar,
Cartesian
}
this comparer:
[Serializable]
public class PolarPositionComparer : IComparer<PolarPosition>
{
...
}
and this PolarPosition:
[Serializable]
public class PolarPosition
{
public double Radius { get; set; }
public double Phi { get; set; }
}
I want to save serialize and deserialize it. I used the answer from this thread: Serializing/deserializing with memory stream and the snippet looks like:
var trajectory1 = new Trajectory {
new PolarPosition(10, 2),
new PolarPosition(11, 2),
new PolarPosition(12, 2)
};
trajectory1.Name = "does ont matter";
trajectory1.UsedCoordinateSystem = CoordinateSystemEnum.Cartesian;
var memoryStreamOfTrajectory1 = SerializeToStream(trajectory1);
var deserializedTrajectory1 = DeserializeFromStream(memoryStreamOfTrajectory1);}
Now my Problem is, that deserializedTrajectory1.Name
is always null
and deserializedTrajectory1.UsedCoordinateSystem
is always Polar
.
What am I doing wrong?