public void RunTest() { //Serialization Logic: RuntimeTypeModel.Default[typeof(SerializeClass)].SetSurrogate(typeof(SerializeClassSurrogate)); var myDictionaryItem = new SerializeDictionaryItem(); myDictionaryItem.MyField = "ABC"; SerializeClass m = new SerializeClass() {MyDictionary = new Dictionary<string, SerializeDictionaryItem>()}; m.MyDictionary.Add("def", myDictionaryItem); m.MyDictionary.Add("abc", myDictionaryItem); m.MyList = new List<SerializeDictionaryItem>(); m.MyList.Add(myDictionaryItem); m.MyList.Add(myDictionaryItem); Assert.AreSame(m.MyDictionary["def"], m.MyDictionary["abc"]); Assert.AreSame(m.MyList[0], m.MyList[1]); byte[] buffer; using (var writer = new MemoryStream()) { Serializer.Serialize(writer, m); buffer = writer.ToArray(); } using(var reader = new MemoryStream(buffer)) { var deserialized = Serializer.Deserialize<SerializeClass>(reader); Assert.AreSame(deserialized.MyDictionary["def"], deserialized.MyDictionary["abc"]); Assert.AreSame(deserialized.MyList[0], deserialized.MyList[1]); } }
public override void Serialize(PackedStream_2 stream) { int count = 0; if (this.Variables != null) { count = this.Variables.Count; } SerializeClass class2 = new SerializeClass(stream, 1, count); for (int i = 0; i < count; i++) { class2.WriteFieldData(this.Variables[i].Field.Id, this.Variables[i].Value.Type.Type, this.Variables[i].VariableId); this.Variables[i].Value.Serialize(stream); } }
public override void Serialize(PackedStream2 stream) { int count = 0; if (Variables != null) { count = Variables.Count; } var serializeClass = new SerializeClass(stream, 1, count); for (int index = 0; index < count; ++index) { serializeClass.WriteFieldData(Variables[index].Field.Id, Variables[index].Value.Type.Type, Variables[index].VariableId); Variables[index].Value.Serialize(stream); } }
public void RunTest() { //Serialization Logic: RuntimeTypeModel.Default[typeof(SerializeClass)].SetSurrogate(typeof(SerializeClassSurrogate)); var myDictionaryItem = new SerializeDictionaryItem(); myDictionaryItem.MyField = "ABC"; SerializeClass m = new SerializeClass() { MyDictionary = new Dictionary <string, SerializeDictionaryItem>() }; m.MyDictionary.Add("def", myDictionaryItem); m.MyDictionary.Add("abc", myDictionaryItem); m.MyList = new List <SerializeDictionaryItem>(); m.MyList.Add(myDictionaryItem); m.MyList.Add(myDictionaryItem); Assert.AreSame(m.MyDictionary["def"], m.MyDictionary["abc"]); Assert.AreSame(m.MyList[0], m.MyList[1]); byte[] buffer; using (var writer = new MemoryStream()) { Serializer.Serialize(writer, m); buffer = writer.ToArray(); } using (var reader = new MemoryStream(buffer)) { var deserialized = Serializer.Deserialize <SerializeClass>(reader); Assert.AreSame(deserialized.MyDictionary["def"], deserialized.MyDictionary["abc"]); Assert.AreSame(deserialized.MyList[0], deserialized.MyList[1]); } }
/// <summary> /// ДеСериализация всех обьектов Базы данных. Клиенты, Администраторы, Тренеры, Расписание груповых тренировок /// </summary> private static void DeSerializeObjects() { var currentPath = Directory.GetCurrentDirectory() + "\\" + Options.FolderNameDataBase + "\\"; // База Клиентов _dataBaseList = new SortedList <string, Person>(StringComparer.OrdinalIgnoreCase); lock (Locker) { SerializeClass.DeSerialize(ref _dataBaseList, currentPath + Options.PersonsDbFile); } // Журнал посещений клиентов _visitsDictionary = new Dictionary <string, List <Visit> >(); SerializeClass.DeSerialize(ref _visitsDictionary, currentPath + Options.PersonVisitsDbFile); // История Абонементов клиента _abonHistoryDictionary = new Dictionary <string, List <AbonHistory> >(); SerializeClass.DeSerialize(ref _abonHistoryDictionary, currentPath + Options.PersonAbonHistDbFile); // База Тренеров _trenersList = new List <Trener>(); SerializeClass.DeSerialize(ref _trenersList, currentPath + Options.TrenersDbFile); // База Администраторов _adminsList = new List <Administrator>(); SerializeClass.DeSerialize(ref _adminsList, currentPath + Options.AdminsDbFile); // Текущий Администратор на Ресепшн _adminCurrent = new Administrator(); SerializeClass.DeSerialize(ref _adminCurrent, currentPath + Options.AdminCurrFile); // Список ежедневных Групповых Тренировок _groupScheduleList = new List <ScheduleNote>(); SerializeClass.DeSerialize(ref _groupScheduleList, currentPath + Options.GroupSchFile); // Списки посещений по группам. Отображаются на главной форме. DailyVisits.GetInstance().DeSerialize(); }
public void RunTest() { Program.ExpectFailure <InvalidOperationException>(() => { //Serialization Logic: RuntimeTypeModel.Default[typeof(SerializeClass)].SetSurrogate(typeof(SerializeClassSurrogate)); var myDictionaryItem = new SerializeDictionaryItem(); myDictionaryItem.MyField = "ABC"; SerializeClass m = new SerializeClass() { MyDictionary = new Dictionary <string, SerializeDictionaryItem>() }; m.MyDictionary.Add("def", myDictionaryItem); m.MyDictionary.Add("abc", myDictionaryItem); m.MyList = new List <SerializeDictionaryItem>(); m.MyList.Add(myDictionaryItem); m.MyList.Add(myDictionaryItem); Assert.AreSame(m.MyDictionary["def"], m.MyDictionary["abc"]); Assert.AreSame(m.MyList[0], m.MyList[1]); byte[] buffer; using (var writer = new MemoryStream()) { Serializer.Serialize(writer, m); buffer = writer.ToArray(); } using (var reader = new MemoryStream(buffer)) { var deserialized = Serializer.Deserialize <SerializeClass>(reader); Assert.AreSame(deserialized.MyDictionary["def"], deserialized.MyDictionary["abc"]); Assert.AreSame(deserialized.MyList[0], deserialized.MyList[1]); } }, "AsReference cannot be used with value-types; please see http://stackoverflow.com/q/14436606/"); }
void RestoreGame() { string p = PlayerPrefs.GetString("GameData_0"); if (p != null && p.Length > 0 && player != null) { s = JsonUtility.FromJson <SerializeClass>(p); if (s != null) { Vector3 position = new Vector3(); if (levelToLoad == 1) { position.x = s.x; position.y = s.y; position.z = s.z; } if (levelToLoad == 2) { position.x = s.x2; position.y = s.y2; position.z = s.z2; } if (levelToLoad == 3) { position.x = s.x3; position.y = s.y3; position.z = s.z3; } if (levelToLoad == 4) { //position.x = s.x4; //position.y = s.y4; //position.z = s.z4; position.x = 43.51358f; position.y = -31.35163f; position.z = 12.8632f; } player.transform.position = position; } } if (p != null && p.Length > 0 && badges1 != null && badges2 != null) { if (s != null) { script1 = badges1.GetComponent <Badges>(); script2 = badges2.GetComponent <Badges>(); if (levelToLoad == 1) { script1.SetBadges(s.badges1_1); script2.SetBadges(s.badges1_2); } if (levelToLoad == 2) { script1.SetBadges(s.badges2_1); script2.SetBadges(s.badges2_2); } if (levelToLoad == 3) { script1.SetBadges(s.badges3_1); script2.SetBadges(s.badges3_2); } if (script1.badgeNumber >= badge1Requirement && script2.badgeNumber >= badge2Requirement) { LockDoor openDoor = lockDoor.GetComponent <LockDoor>(); openDoor.Unlock(); } } } }