将对象列表保存到XML文件并使用C#加载该列表的最佳方法是什么?

前端之家收集整理的这篇文章主要介绍了将对象列表保存到XML文件并使用C#加载该列表的最佳方法是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序中有一个“Gesture”类列表:

List<Gesture> gestures = new List<Gesture>();

这些手势类非常简单:

public class Gesture
{
    public String Name { get; set; }
    public List<Point> Points { get; set; }
    public List<Point> TransformedPoints { get; set; }    

    public Gesture(List<Point> Points,String Name)
    {
        this.Points = new List<Point>(Points);
        this.Name = Name;
    }
}

我想允许用户将“手势”的当前状态保存到文件中,并且还能够加载包含手势数据的文件.

在C#中执行此操作的标准方法是什么?

我应该使用序列化吗?我应该自己编写一个类来处理这个XML文件的编写/读取吗?还有其他方法吗?

解决方法

看一下.net中的XmlSerializer类型和XmlSerialization

在这里……找到了一个可以满足你需求的例子
http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization

猜你在找的XML相关文章