public object DeserializeArray(Type type, BinaryReader reader) { var length = reader.ReadInt32(); var obj = CoreUtil.CreateInstance(type, new object[] { length }) as Array; for (var i = 0; i < obj.Length; i++) { var index = i; Deserialize(reader, ret => obj.SetValue(ret, index)); } return(obj); }
private void InitCustomPersistence() { mCustomPersistenceMap = new Dictionary <Type, CustomPersistence>(); mCustomGenericPersistenceMap = new Dictionary <Type, CustomPersistence>(); var customTypes = CoreUtil.FindSubTypes(typeof(CustomPersistence)); foreach (var type in customTypes) { var instance = (CustomPersistence)CoreUtil.CreateInstance(type, new object[] { this }); if (instance.persistentType.IsGenericTypeDefinition) { mCustomGenericPersistenceMap.Add(instance.persistentType, instance); } else { mCustomPersistenceMap.Add(instance.persistentType, instance); } } }
public object DeserializeConstruction(Type type, bool instance, BinaryReader reader) { var obj = instance ? CoreUtil.CreateInstance(type) : null; var fieldCount = reader.ReadInt32(); for (var i = 0; i < fieldCount; i++) { var fieldName = reader.ReadString(); var field = mCache.GetField(type, fieldName, instance); Debug.Assert(field != null, type.FullName + "." + fieldName + " is not exist or writable."); Deserialize(reader, ret => { if (field != null) { field.SetValue(obj, ret); } }); } var propertyCount = reader.ReadInt32(); for (var i = 0; i < propertyCount; i++) { var propertyName = reader.ReadString(); var property = mCache.GetProp(type, propertyName, instance); Debug.Assert(property != null, type.FullName + "." + propertyName + " is not exist or writable."); Deserialize(reader, ret => { if (property != null) { property.SetValue(obj, ret, null); } }); } return(obj); }