[英]how to serialize a point3D using XmlSerializer?
public class Placement
{
public Point3D Location { get; set; }
public Point3D Axis { get; set; }
public Point3D Direction { get; set; }
}
public class Attribute1
{
public string Key { get; set; }
public Type Type { get; set; }
public Object Value { get; set; }
}
class Program
{
static void Main(string[] args)
{
Attribute1 a = new Attribute1();
a.Key = "test";
var p = new Placement();
p.Axis = new Point3D(12.0, 22.09, 0);
p.Location = new Point3D(12.0, 22.09, 0);
p.Direction = new Point3D(12.0, 22.09, 0);
a.Value = p;
var serializer = new XmlSerializer(typeof(Attribute1));
var path = "E:\\details.xml";
using (TextWriter writer = new StreamWriter(path))
{
serializer.Serialize(writer, a);
}
Console.Read();
}
}
我正在尝试使用XmlSerializer
序列化Point3D
。 我正在使用XmlSerializer
序列化包含Attribute1
的类的其他属性,但是序列化时出现错误。 请让我知道如何实现这一目标或向我指出相关资源。 谢谢!
您已经告诉您要序列化Attribute1,而不要序列化Placement。 只需更改这一行:
var serializer = new XmlSerializer(typeof(Attribute1), new Type[] { typeof(Placement) });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.