コード例 #1
0
        public override object Deserialize(ContextDeserialization context)
        {
            // Result
            var res = new List <object>();

            // Burn bracket open, "["
            context.Burn(1);
            // Go to first element
            context.BurnWhitespaces();
            // Loop until we hit brackend end
            var isFirst = true;

            while (context.ReadChar() != ']')
            {
                // If not first element, need to burn the ","
                if (!isFirst)
                {
                    context.Burn(1);
                    context.BurnWhitespaces();
                }
                isFirst = false;
                // Read the generic element
                res.Add(context.ReadGeneric());
                // Go to next stop
                context.BurnWhitespaces();
            }
            // Burn bracket end, "]"
            context.Burn(1);
            // Done, return list
            return(res);
        }
コード例 #2
0
ファイル: Serializer.cs プロジェクト: yuzhimin999/calcflow
        public T DeserializeString <T>(string str)
        {
            var context = new ContextDeserialization(str);

            context.deserializers = deserializers;
            var result = (T)context.ReadGeneric();

            context.Close();
            return(result);
        }
コード例 #3
0
        public override object Deserialize(ContextDeserialization context)
        {
            // Result
            var res = new Dictionary <string, object>();

            // Burn bracket open, "{"
            context.Burn(1);
            // Go to first element
            context.BurnWhitespaces();
            // Loop until we hit brackend end, "}"
            var isFirst = true;

            while (context.ReadChar() != '}')
            {
                // If not first element, need to burn the ","
                if (!isFirst)
                {
                    context.Burn(1);
                    context.BurnWhitespaces();
                }
                isFirst = false;
                // Read the generic key
                var key = (string)context.ReadGeneric();
                // Go to key delimiter
                context.BurnWhitespaces();
                // Burn key delimiter, ":"
                context.Burn(1);
                // go to value
                context.BurnWhitespaces();
                // Read the generic element
                var value = context.ReadGeneric();
                // Save result
                res[key] = value;
                // Go to next stop
                context.BurnWhitespaces();
            }
            // Burn bracket end, "}"
            context.Burn(1);
            // Done, return list
            return(res);
        }