/// <summary>
        /// 将源字符串分析为 Lambda 表达式树.
        /// </summary>
        /// <typeparam name="T">委托类型</typeparam>
        /// <param name="source">用于分析的源字符串.</param>
        /// <param name="ns">分析过程中可能用到的命名空间列表.</param>
        /// <returns>分析完成的 Lambda 表达式树.</returns>
        public static Expression <T> Parse <T>(string source, params string[] ns)
        {
            var parseResult = SymbolParser.Build(source);
            var parser      = new ExpressionParserCore(parseResult, typeof(T), ns, null);

            return(parser.ToLambdaExpression <T>());
        }
        /// <summary>
        /// 将源字符串分析为委托.
        /// </summary>
        /// <typeparam name="T">委托类型</typeparam>
        /// <param name="source">用于分析的源字符串.</param>
        /// <param name="assemblies">可能用到的程序集列表.</param>
        /// <param name="ns">分析过程中可能用到的命名空间列表.</param>
        /// <returns>
        /// 分析委托.
        /// </returns>
        public static T Compile <T>(string source, Assembly[] assemblies, params string[] ns)
        {
            var parseResult = SymbolParser.Build(source);
            var parser      = new ExpressionParserCore(parseResult, typeof(T), ns, assemblies);

            return(parser.ToLambdaExpression <T>().Compile());
        }
        /// <summary>
        /// Builds the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>The Build result.</returns>
        public static SymbolParseResult Build(string source)
        {
            var          item = new SymbolParser(source);
            List <Token> data = new List <Token>();

            while (true)
            {
                var token = item.NextToken();
                data.Add(token);
                if (token.ID == TokenId.End)
                {
                    break;
                }
            }
            return(new SymbolParseResult(data));
        }
Beispiel #4
0
        /// <summary>
        /// 解析字符串为类型
        /// </summary>
        /// <returns>读取的类型</returns>
        public Type Resolve(string typeString)
        {
            spResult = SymbolParser.Build(typeString);

            return(ReadType());
        }