Exemple #1
0
        internal Type ReadType(string typeName = null, bool ignoreException = false)
        {
            Type          type    = null;
            StringBuilder sbValue = new StringBuilder(string.IsNullOrEmpty(typeName) ? spResult.Next().Text : typeName);

            do
            {
                // 读取参数
                if (spResult.IsGenericType())
                {
                    spResult.Skip();
                    List <Type> types = new List <Type>();
                    while (true)
                    {
                        types.Add(ReadType());
                        if (spResult.PeekNext().Is(OperatorWord.Comma))
                        {
                            spResult.Skip();
                        }
                        else
                        {
                            break;
                        }
                    }
                    spResult.Next().Is(OperatorWord.RightAngleBracket, true);

                    sbValue.AppendFormat("`{0}[{1}]", types.Count, string.Join(",", types.Select(p => "[" + p.AssemblyQualifiedName + "]").ToArray()));
                }

                type = GetType(sbValue.ToString());
                if (type == null)
                {
                    var token = spResult.Next();
                    if (!token.Is(OperatorWord.Dot))
                    {
                        if (ignoreException)
                        {
                            break;
                        }

                        throw new ArgumentException(string.Format("Unsupported {0}", token.Text));
                    }
                    sbValue.Append(".");
                    sbValue.Append(spResult.Next().Text);
                }
            } while (type == null);

            return(type);
        }
        /// <summary>
        /// 读取表达式
        /// </summary>
        /// <param name="level">优先级别</param>
        /// <returns>ReadResult</returns>
        private ReadResult ReadExpression(int level = 0)
        {
            var exp = ReadFirstExpression();

            int nextLevel = 0;
            var next      = spResult.PeekNext();

            while (!exp.IsClosedWrap && (nextLevel = OperatorPriority.GetOperatorLevel(next.Text)) > level)
            {
                exp  = ReadNextExpression(nextLevel, exp);
                next = spResult.PeekNext();
            }

            return(exp);
        }