コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: BinaryDeserializer.cs プロジェクト: grofit/LazyData
        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);
                }
        }
コード例 #6
0
ファイル: BsonDeserializer.cs プロジェクト: grofit/LazyData
        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);
        }