private SerializedList DeserializeList(BinaryReader reader) { var value = new SerializedList(DeserializeDefaults(reader)); var count = reader.ReadInt32(); for (int i = 0; i < count; i++) { var mode = (ESerializableMode)reader.ReadInt32(); switch (mode) { case ESerializableMode.Primitive: value.Add(DeserializePrimitive(reader)); break; case ESerializableMode.Enum: value.Add(DeserializeEnum(reader)); break; case ESerializableMode.List: value.Add(DeserializeList(reader)); break; case ESerializableMode.Class: value.Add(DeserializeClass(reader)); break; default: break; } } return(value); }
private SerializedList SerializeList(object value, Type valueType) { if (value == null) { return(new SerializedList(GetNextID(), valueType.AssemblyQualifiedName) { IsNull = true }); } var list = new SerializedList(GetNextID(), valueType.AssemblyQualifiedName); if (Compare(value, valueType, ref list.ID)) { list.IsReference = true; return(list); } else { AddToComparables(list, value, valueType); } var vList = (IList)value; var vCount = vList.Count; Type vType = null; if (valueType.IsArray()) { vType = valueType.GetElementType(); if (valueType == typeof(Array)) { for (int i = 0; i < vList.Count; i++) { var item = vList[i]; if (item != null) { vType = item.GetType(); break; } } } if (vType == null) { vType = typeof(object); } } else { vType = valueType.GetGenericArguments()[0]; } Func <object, Type, SerializedBase> method = null; bool isClass = false; if (vType.IsArray()) { method = SerializeList; } else if (vType.IsEnum) { method = SerializeEnum; } else if (vType.IsValueType && !vType.IsPrimitive) { if (vType == typeof(decimal)) { method = SerializePrimitive; } else { method = SerializeClass; isClass = true; } } else if (vType.IsValueType) { method = SerializePrimitive; } else if (vType.IsClass) { if (vType == typeof(string)) { method = SerializePrimitive; } else if (vType.IsList()) { method = SerializeList; } else { method = SerializeClass; isClass = true; } } for (int i = 0; i < vCount; i++) { if (isClass) { var v = vList[i]; if (v == null) { list.Add(method(v, vType)); } else { list.Add(method(v, v.GetType())); } } else { list.Add(method(vList[i], vType)); } } return(list); }