예제 #1
0
        public static Expression <T> Parse <T>(string source)
        {
            var parseResult = SymbolParser.Build(source);
            var parser      = new ExpressionParserCore(parseResult, typeof(T), null, null);

            return(parser.ToLambdaExpression <T>());
        }
예제 #2
0
        /// <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());
        }
예제 #3
0
        /// <summary>
        /// 将源字符串分析为委托.
        /// </summary>
        /// <typeparam name="T">委托类型</typeparam>
        /// <param name="source">用于分析的源字符串.</param>
        /// <param name="ns">分析过程中可能用到的命名空间列表.</param>
        /// <returns>分析委托.</returns>
        public static Func <T, bool> Compile <T>(string source, params string[] ns)
        {
            var parseResult = SymbolParser.Build(source);
            var parser      = new ExpressionParserCore <T>(parseResult, typeof(T), ns, null);

            return(parser.ToLambdaExpression <T>().Compile());
        }
예제 #4
0
        /// <summary>
        /// 解析Lambda表达式代码
        /// </summary>
        /// <param name="lambdaCode">lambda表达式代码。如:m=>m.ToString()</param>
        /// <param name="namespaces">命名空间集</param>
        static private LambdaExpression ParseCore <TDelegate>(Type delegateType, string lambdaCode, Type defaultInstanceType, bool firstTypeIsDefaultInstance, Type[] paramTypes, params string[] namespaces)
        {
            ExpressionParserCore <TDelegate> parser = new ExpressionParserCore <TDelegate>(delegateType, lambdaCode, defaultInstanceType, paramTypes, firstTypeIsDefaultInstance);

            if (namespaces != null && namespaces.Length > 0)
            {
                parser.Namespaces.AddRange(namespaces);
            }
            return(parser.ToLambdaExpression());
        }