Ejemplo n.º 1
0
        object ISerializerInternal.DeserializeInternal(string data, DeserializationContext context)
        {
            if (data.Equals(EmptySymbol))
            {
                return(EmptyValue);
            }

            MainParser        parser = new MainParser();
            IList <INodeData> list;

            parser.ExtractNodeData(data, out list);

            // get the metadata
            List <INodeData> validNodes = list[0].SubNodes[1].SubNodes.Where(n => !NodeUtils.IgnoreOnDeserialization(n.Type)).ToList();

            INodeData typeNode = list[0].SubNodes[1].SubNodes.FirstOrDefault(n => n.Type == NodeType.METADATA);

            CustomSerializer serializer = SerializerUtils.MetadataSerializer;

            Metadata metadata = (Metadata)serializer.ReadObjectData(new List <INodeData>()
            {
                typeNode
            }, context, -1);

            // check if the object is already in cache
            // if that's the case then return it
            if (context.TryGet(metadata.ReferenceTracker, out object cacheFound))
            {
                return(cacheFound);
            }

            // validate the node structure
            if (!ValidateNodes(list))
            {
                return(EmptyValue);
            }

            // else do the normal deserialization
            object result = ReadObjectData(list, context, metadata.ReferenceTracker);

            return(result);
        }