public static bool DeserializeTypeless(object obj, IReader reader) { Type type = obj.GetType(); DeserializationMapping deserializationMapping = Manager.GetDeserializationMapping(type); try { return(deserializationMapping.Deserialize(obj, reader)); } catch (Exception ex) { string text = $"Exception occurred while attempting to deserialize object {obj}({obj.GetType()}).\n{ex.ToString()}"; DebugLog.Output(DebugLog.Level.Error, text); throw new Exception(text, ex); } }
private static DeserializationMapping GetMapping(DeserializationTemplate dtemplate, SerializationTemplate stemplate) { DeserializationMapping deserializationMapping = null; if (deserializationMappings.TryGetValue(dtemplate, out KeyValuePair <SerializationTemplate, DeserializationMapping> value)) { deserializationMapping = value.Value; } else { deserializationMapping = new DeserializationMapping(dtemplate, stemplate); value = new KeyValuePair <SerializationTemplate, DeserializationMapping>(stemplate, deserializationMapping); deserializationMappings[dtemplate] = value; } return(deserializationMapping); }
public static bool Deserialize(Type type, IReader reader, out object result) { DeserializationMapping deserializationMapping = Manager.GetDeserializationMapping(type); try { object obj = Activator.CreateInstance(type); bool result2 = deserializationMapping.Deserialize(obj, reader); result = obj; return(result2); } catch (Exception ex) { string text = $"Exception occurred while attempting to deserialize into object of type {type.ToString()}.\n{ex.ToString()}"; DebugLog.Output(DebugLog.Level.Error, text); throw new Exception(text, ex); } }
/// <summary> /// Gets the deserialization mapping for the specified type. /// </summary> /// <param name="type">The type to look up.</param> /// <returns>The deserialization mapping for that type.</returns> public static DeserializationMapping GetKleiDeserializationMapping(Type type) { var dtemplate = GetDeserializationTemplate(type); if (dtemplate == null) { throw new ArgumentException("Tried to deserialize a class named: " + type.GetKTypeString() + " but no such class exists"); } var stemplate = GetKleiSerializationTemplate(type); if (stemplate == null) { throw new ArgumentException("Tried to deserialize into a class named: " + type.GetKTypeString() + " but no such class exists"); } if (!MAPPINGS_LEGACY.TryGetValue(dtemplate, out DeserializationMapping mapping)) { mapping = new DeserializationMapping(dtemplate, stemplate); MAPPINGS_LEGACY.Add(dtemplate, mapping); } return(mapping); }
/// <summary> /// Applied before GetDeserializationMapping runs. /// </summary> internal static bool Prefix(Type type, ref DeserializationMapping __result) { __result = FastSerializationManager.GetKleiDeserializationMapping(type); return(false); }