예제 #1
0
    static void BinarySerializeRead()
    {
        FileStream      fileStream = new FileStream("ABCfg.bytes", FileMode.Open, FileAccess.Read, FileShare.Read);
        BinaryFormatter bf         = new BinaryFormatter();
        ABCfg           cfg        = bf.Deserialize(fileStream) as ABCfg;

        Debug.Log(cfg.Id);
        Debug.Log(cfg.Name);
        foreach (var item in cfg.List)
        {
            Debug.Log(item);
        }
    }
예제 #2
0
    static void XmlSerilize_read()
    {
        FileStream    fileStream = new FileStream("ABCfg.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
        StreamReader  sr         = new StreamReader(fileStream, System.Text.Encoding.UTF8);
        XmlSerializer xml        = new XmlSerializer(typeof(ABCfg));
        ABCfg         cfg        = xml.Deserialize(sr) as ABCfg;

        Debug.Log(cfg.Id);
        Debug.Log(cfg.Name);
        Debug.Log(cfg.List);
        sr.Close();
        fileStream.Close();
    }
예제 #3
0
    static void BinarySerializeWrite()
    {
        ABCfg cfg = new ABCfg();

        cfg.Id   = 3;
        cfg.Name = "测试3";
        cfg.List = new List <int>()
        {
            2, 3, 4
        };
        FileStream      fileStream = new FileStream("ABCfg.bytes", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
        BinaryFormatter bf         = new BinaryFormatter();

        bf.Serialize(fileStream, cfg);
        fileStream.Close();
    }
예제 #4
0
    static void XmlSerilize()
    {
        ABCfg cfg = new ABCfg();

        cfg.Id   = 1;
        cfg.Name = "测试";
        cfg.List = new List <int>()
        {
            1, 2, 3, 4
        };

        FileStream    fileStream = new FileStream("ABCfg.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
        StreamWriter  sw         = new StreamWriter(fileStream, System.Text.Encoding.UTF8);
        XmlSerializer xml        = new XmlSerializer(typeof(ABCfg));

        xml.Serialize(sw, cfg);
        sw.Close();
        fileStream.Close();
    }