Exemple #1
0
        private static SyntaxObjectNode ParseNodeFromObject(Type ObjType, object Obj)
        {
            var Node   = new SyntaxObjectNode();
            var Fileds = ObjType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var Filed in Fileds)
            {
                var FiledValue = Filed.GetValue(Obj);
                var FiledNode  = ParseNodeFromValue(Filed.FieldType, FiledValue);
                Node.AddChild(Filed.Name, FiledNode);
            }

            return(Node);
        }
Exemple #2
0
        private SyntaxObjectNode ParseObject()
        {
            if (TokensStream_.Take().Code_ != LanguageDescriptor.JsonObjectBegin)
            {
                Logger.Add(TokensStream_.Peek().Line_, TokensStream_.Peek().Index_, $"expected '{LanguageDescriptor.JsonObjectBegin}' not appeared");
                return(null);
            }

            var Node = new SyntaxObjectNode();

            while (!TokensStream_.IsEnd())
            {
                if (TokensStream_.Peek().Code_ == LanguageDescriptor.JsonObjectEnd)
                {
                    break;
                }

                var Key = ParseKey();
                if (string.IsNullOrWhiteSpace(Key))
                {
                    return(null);
                }

                if (TokensStream_.Take().Code_ != LanguageDescriptor.JsonDefineDelimiter)
                {
                    Logger.Add(TokensStream_.Peek().Line_, TokensStream_.Peek().Index_, $"expected '{LanguageDescriptor.JsonDefineDelimiter}' not appeared");
                    return(null);
                }

                var Value = ParseValue();
                if (Value == null)
                {
                    return(null);
                }

                Node.AddChild(Key, Value);

                if (TokensStream_.Peek().Code_ == LanguageDescriptor.JsonValueDelimiter)
                {
                    TokensStream_.Take();
                }
            }

            TokensStream_.Take();
            return(Node);
        }