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); Type instanceType; Metadata metadata; if (!CanDeserialize(list, out instanceType, out metadata, context)) { return(EmptyValue); } if (context.TryGet(metadata.ReferenceTracker, out object cacheFound)) { return(cacheFound); } ISerializer concreteSerializer = SerializerDependencies.SerializerCollection.GetOrAdd(instanceType); return(((CustomSerializer)concreteSerializer).ReadObjectData(list, context, metadata.ReferenceTracker)); }
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); }
public bool IsValid(string data, out IList <INodeData> nodeDatas, int position, out string patched) { if (string.IsNullOrEmpty(data)) { nodeDatas = null; patched = data; return(false); } if (data.Length < 2) { nodeDatas = null; patched = data; return(false); } cachedList.Clear(); int startIndex; int endIndex; AllIndexesOf(data, START_SYMBOL, cachedList); if (cachedList.Count == 0) { nodeDatas = null; patched = data; return(false); } startIndex = cachedList[0]; AllIndexesOf(data, END_SYMBOL, cachedList); if (cachedList.Count == 0) { nodeDatas = null; patched = data; return(false); } endIndex = cachedList[0]; if (startIndex != 0) { patched = data; nodeDatas = new List <INodeData>(); return(false); } var content = data.Substring(startIndex + 1, endIndex - startIndex - 1); var fullText = data.Substring(startIndex, endIndex - startIndex + 1); NodeDataBase obj = new NodeDataBase(NodeType, fullText, position); nodeDatas = new List <INodeData>(1); INodeData symbolStart = new NodeDataBase(NodeType.SYMBOL, START_SYMBOL, position); INodeData nodeData = new NodeDataBase(NodeType.METADATA_CONTENT, content, position); INodeData symbolEnd = new NodeDataBase(NodeType.SYMBOL, END_SYMBOL, position); var firstPart = data.Substring(0, startIndex); var secondPart = data.Substring(endIndex + 1, data.Length - 1 - endIndex); patched = firstPart + secondPart; MainParser mainParser = new MainParser(); IList <INodeData> list; mainParser.ExtractNodeData(content, out list); nodeData.SubNodes.AddRange(list); obj.SubNodes.Add(symbolStart); obj.SubNodes.Add(nodeData); obj.SubNodes.Add(symbolEnd); nodeDatas.Add(obj); return(true); }