public static void TestSystem() { Test_ToXml tester = new Test_ToXml { Name = "A" }; tester.SerializableVal.OtherVal = new Test_ToXml { Name = "B" }; tester.SerializableVal.OtherVal.SerializableVal.OtherVal = new Test_ToXml { Name = "C" }; tester.SerializableVal.OtherVal.SerializableVal.OtherVal.SerializableVal.OtherVal = new Test_ToXml { Name = "D" }; tester.SerializableVal.OtherVal.SerializableVal.OtherVal.SerializableVal.OtherVal.SerializableVal.OtherVal = tester.SerializableVal.OtherVal; tester.RandomField(); XElement element = FrogSerialization.Serialize(tester); element.Save("Log.log"); object result = null; FrogSerialization.Deserialize(element, ref result); if (!tester.ValueEqual(result as Test_ToXml, new List <Test_ToXmlBase>())) { throw new Exception("反序列化生成结果异常"); } Test_ToXml copy = new Test_ToXml(); result = copy; FrogSerialization.Deserialize(element, ref result); if (!tester.ValueEqual(result as Test_ToXml, new List <Test_ToXmlBase>())) { throw new Exception("反序列化修改结果异常"); } EditorUtility.DisplayDialog("消息", "测试完成", "确定"); }
/// <summary> /// 数据相同验证 /// </summary> /// <param name="tester">测试对象</param> /// <param name="listHasTest">已测试对象</param> /// <returns>测试结果</returns> public bool ValueEqual(Test_ToXml tester, List <Test_ToXmlBase> listHasTest) { if (listHasTest.Contains(this)) { return(true); } listHasTest.Add(this); if (tester == null) { throw new Exception("Null object to test."); } if (ParentField != tester.ParentField) { throw new Exception($"{nameof(ParentField)} is not equal!"); } if (BoolVal != tester.BoolVal) { throw new Exception($"{nameof(BoolVal)} is not equal!"); } if (ByteVal != tester.ByteVal) { throw new Exception($"{nameof(ByteVal)} is not equal!"); } if (CharVal != tester.CharVal) { throw new Exception($"{nameof(CharVal)} is not equal!"); } if (DecimalVal != tester.DecimalVal) { throw new Exception($"{nameof(DecimalVal)} is not equal!"); } if (DoubleVal != tester.DoubleVal) { throw new Exception($"{nameof(DoubleVal)} is not equal!"); } if (EnumVal != tester.EnumVal) { throw new Exception($"{nameof(EnumVal)} is not equal!"); } if (FloatVal != tester.FloatVal) { throw new Exception($"{nameof(FloatVal)} is not equal!"); } if (IntVal != tester.IntVal) { throw new Exception($"{nameof(IntVal)} is not equal!"); } if (LongVal != tester.LongVal) { throw new Exception($"{nameof(LongVal)} is not equal!"); } if (SByteVal != tester.SByteVal) { throw new Exception($"{nameof(SByteVal)} is not equal!"); } if (ShortVal != tester.ShortVal) { throw new Exception($"{nameof(ShortVal)} is not equal!"); } if (StringVal != tester.StringVal) { throw new Exception($"{nameof(StringVal)} is not equal!"); } if (UIntVal != tester.UIntVal) { throw new Exception($"{nameof(UIntVal)} is not equal!"); } if (ULongVal != tester.ULongVal) { throw new Exception($"{nameof(ULongVal)} is not equal!"); } if (UShortVal != tester.UShortVal) { throw new Exception($"{nameof(UShortVal)} is not equal!"); } if (MaterialVal.color != tester.MaterialVal.color) { throw new Exception($"{nameof(MaterialVal)} is not equal!"); } if (NonSerializedInt == tester.NonSerializedInt) { throw new Exception($"{nameof(NonSerializedInt)} is not equal!"); } if (!(SerializableVal).ValueEqual(tester.SerializableVal, listHasTest)) { throw new Exception($"{nameof(SerializableVal)} is not equal!"); } if (ArrayVal.Count() != tester.ArrayVal.Count()) { throw new Exception($"{nameof(ArrayVal)} count is not equal!"); } for (int i = 0; i < ArrayVal.Count(); i++) { if (!ArrayVal[i].ValueEqual(tester.ArrayVal[i], listHasTest)) { throw new Exception($"{nameof(ArrayVal)}[{i}] count is not equal!"); } } if (ListVal.Count != tester.ListVal.Count) { throw new Exception($"{nameof(ListVal)} count is not equal!"); } for (int i = 0; i < ListVal.Count; i++) { if (!ListVal[i].ValueEqual(tester.ListVal[i], listHasTest)) { throw new Exception($"{nameof(ListVal)}[{i}] count is not equal!"); } } if (DictionaryVal.Count != tester.DictionaryVal.Count) { throw new Exception($"{nameof(DictionaryVal)} count is not equal!"); } for (int i = 0; i < DictionaryVal.Count; i++) { if (!DictionaryVal[i].ValueEqual(tester.DictionaryVal[i], listHasTest)) { throw new Exception($"{nameof(DictionaryVal)}[{i}] count is not equal!"); } } return(true); }