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();
}
}
我正在尝试使用Point3D
序列化XmlSerializer
。
我使用XmlSerializer
来序列化包含Attribute1
的类的其他属性
但序列化时出错。
请让我知道如何实现这一目标或指向相关资源。谢谢!
答案 0 :(得分:0)
您告诉它您要序列化Attribute1但不要序列化Placement。只需改变这一行:
var serializer = new XmlSerializer(typeof(Attribute1), new Type[] { typeof(Placement) });