예제 #1
0
        public static void Save <T>(T saveObject, ushort slot) where T : class
        {
            byte[] serializedData;
            string path = AddSlotPath(SaveFolderPath, slot);

            // データのシリアライズ
            XmlSerializeHelper.SerializeToByte <T>(saveObject, out serializedData);

            // データをバイナリで書き込み
            using (var stream = new FileStream(path, FileMode.Create))
            {
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write(serializedData);
                }
            }
        }
예제 #2
0
        public static T Load <T>(ushort slot) where T : class
        {
            string path = AddSlotPath(SaveFolderPath, slot);

            if (new FileInfo(path).Exists == false)
            {
                // ファイルがない場合はデフォルトの指定クラスを返す
                return(default(T));
            }

            byte[] readData;

            // データの読み込み
            using (var stream = new FileStream(path, FileMode.Open))
            {
                using (var reader = new BinaryReader(stream))
                {
                    readData = reader.ReadBytes((int)reader.BaseStream.Length);
                }
            }

            // データのデシリアライズ
            return(XmlSerializeHelper.DeserializeFromByte <T>(ref readData));
        }