I have this set of code, but what I'd really like is to make x and y readonly public, or public only with a getter exposed. Normally in C++ you'd make the serializer a friend class. Is there an equivalent trick in C#?
public struct z
{
public int x;
public int y;
public z(int a, int b)
{
x = a;
y = b;
}
}
class Program
{
static void Main(string[] args)
{
List<z> b = new List<z>();
b.Add(new z(3, 4));
System.Xml.Serialization.XmlSerializer w = new System.Xml.Serialization.XmlSerializer(typeof(List<z>));
System.IO.StringWriter x = new System.IO.StringWriter();
w.Serialize(x,b);
System.IO.StringReader y = new System.IO.StringReader(x.ToString());
List<z> c = (List<z>)w.Deserialize(y);
Console.WriteLine(b[0].x);
Console.WriteLine(c[0].x);
}
}