コード例 #1
0
        private void DeserializeObject()
        {
            string        path = @"D:\serial.bin";
            Wrapper       typeList;
            Serializators objectDeserializer = new Serializators();

            JsonSerializer serializer = new JsonSerializer();
            MemoryStream   ms         = new MemoryStream();
            string         data       = string.Empty;

            data = System.IO.File.ReadAllText(path);
            string[]     dataList = data.Split(' ');
            byte[]       bdata    = Convert.FromBase64String(dataList[dataList.Length - 1]);
            MemoryStream ms1      = new MemoryStream(bdata);

            using (BsonReader reader = new BsonReader(ms1))
            {
                JsonSerializer deserializer = new JsonSerializer();
                typeList = deserializer.Deserialize <Wrapper>(reader);
            }

            for (int i = 0; i < typeList.Content.Count; i++)
            {
                transports.Add(objectDeserializer.Serialize(typeList.Content[i], dataList[i]));
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Gramazski/Serialize_Lab
        private void SerializeObject()
        {
            ListOfTypes    typeList      = new ListOfTypes();
            string         path          = @"serial.bin";
            string         data          = string.Empty;
            string         serializeData = string.Empty;
            JsonSerializer serializer    = new JsonSerializer();

            foreach (ITransport transport in transports)
            {
                serializeData = objectDeserializer.Serialize(transport.GetType(), transport);
                typeList.Content.Add(transport.GetType());
                data += serializeData + " ";
            }

            MemoryStream ms1 = new MemoryStream();

            BsonWriter writer1 = new BsonWriter(ms1);

            serializer.Serialize(writer1, typeList);
            data += Convert.ToBase64String(ms1.ToArray());

            System.IO.File.WriteAllText(path, data);
        }