public override void DeserializeInto(DataObject data, object existingInstance) { JObject jsonData; using (var memoryStream = new MemoryStream(data.AsBytes)) using (var bsonReader = new BsonReader(memoryStream)) { jsonData = (JObject)JToken.ReadFrom(bsonReader); } var typeName = jsonData[JsonSerializer.TypeField].ToString(); var type = TypeCreator.LoadType(typeName); var typeMapping = MappingRegistry.GetMappingFor(type); Deserialize(typeMapping.InternalMappings, existingInstance, jsonData); }
public override object Deserialize(DataObject data, Type type = null) { var jsonData = JObject.Parse(data.AsString); if (type == null) { var typeName = jsonData[JsonSerializer.TypeField].ToString(); type = TypeCreator.LoadType(typeName); } var typeMapping = MappingRegistry.GetMappingFor(type); var instance = Activator.CreateInstance(type); Deserialize(typeMapping.InternalMappings, instance, jsonData); return(instance); }
protected virtual object DeserializeDynamicTypeData(TDeserializeState state) { var dynamicTypeName = GetDynamicTypeNameFromState(state); var instanceType = TypeCreator.LoadType(dynamicTypeName); var dataState = GetDynamicTypeDataFromState(state); if (MappingRegistry.TypeMapper.TypeAnalyzer.IsPrimitiveType(instanceType)) { return(DeserializePrimitive(instanceType, dataState)); } var instance = TypeCreator.Instantiate(instanceType); var typeMapping = MappingRegistry.GetMappingFor(instanceType); Deserialize(typeMapping.InternalMappings, instance, dataState); return(instance); }
public override object Deserialize(DataObject data, Type type = null) { var xDoc = XDocument.Parse(data.AsString); var containerElement = xDoc.Element(XmlSerializer.ContainerElementName); if (type == null) { var typeName = containerElement.Attribute(XmlSerializer.TypeAttributeName).Value; type = TypeCreator.LoadType(typeName); } var typeMapping = MappingRegistry.GetMappingFor(type); var instance = Activator.CreateInstance(typeMapping.Type); Deserialize(typeMapping.InternalMappings, instance, containerElement); return(instance); }
public override object Deserialize(DataObject data, Type type = null) { using (var memoryStream = new MemoryStream(data.AsBytes)) using (var reader = new BinaryReader(memoryStream)) { var containsType = reader.ReadBoolean(); if (containsType) { var typeName = reader.ReadString(); if (type == null) { type = TypeCreator.LoadType(typeName); } } var typeMapping = MappingRegistry.GetMappingFor(type); var instance = Activator.CreateInstance(type); Deserialize(typeMapping.InternalMappings, instance, reader); return(instance); } }
public override object Deserialize(DataObject data, Type type = null) { JObject jsonData; using (var memoryStream = new MemoryStream(data.AsBytes)) using (var bsonReader = new BsonReader(memoryStream)) { jsonData = (JObject)JToken.ReadFrom(bsonReader); } if (type == null) { var typeName = jsonData[JsonSerializer.TypeField].ToString(); type = TypeCreator.LoadType(typeName); } var typeMapping = MappingRegistry.GetMappingFor(type); var instance = Activator.CreateInstance(type); Deserialize(typeMapping.InternalMappings, instance, jsonData); return(instance); }