public IEnumerable <ExpressionInfo> DoAnalyse(string expression) { IKeyWordProvider keyWordProvider = UtilContainer.Resolve <IKeyWordProvider>(); var param = keyWordProvider.Param; if (expression.IndexOf(param) < 0) { return(Enumerable.Empty <ExpressionInfo>()); } IExpressionInfoBuilder builder = UtilContainer.Resolve <IExpressionInfoBuilder>(); ICollection <ExpressionInfo> expressionInfos = new List <ExpressionInfo>(); var paramStrArray = expression.Split(keyWordProvider.SplitChar).Where(p => p.StartsWith(keyWordProvider.Param)).Select(p => p.Replace(keyWordProvider.Param, string.Empty)).ToArray(); int index = 0; foreach (var paramStr in paramStrArray) { var ei = builder.Build(expression, paramStr, keyWordProvider); ei.StartIndex = expression.IndexOf(paramStr, index); index = paramStr.Length + ei.StartIndex; expressionInfos.Add(ei); } return(expressionInfos); }
public string Regular(string expression, IEnumerable <ExpressionInfo> expressionInfos, Expression exps, IEnumerable <Type> staticTypes) { foreach (var expressionInfo in expressionInfos.OrderByDescending(e => e.StartIndex)) { var regular = Create(expressionInfo); if (regular == null) { continue; } expression = regular.Regular(expression, expressionInfo, exps, staticTypes); } IKeyWordProvider keyWordProvider = UtilContainer.Resolve <IKeyWordProvider>(); return(expression.Replace(keyWordProvider.Param, string.Empty)); }
public ExpressionInfo Build(string expression, string paramStr, IKeyWordProvider provider) { ParamMode mode; if (paramStr.StartsWith(provider.ExpressionString)) { mode = ParamMode.Expression; } else if (paramStr.StartsWith(provider.FuncString)) { mode = ParamMode.Func; } else { mode = ParamMode.Param; } return(Build(expression, mode, paramStr, provider)); }
protected ExpressionInfo Build(string expression, ParamMode mode, string paramStr, IKeyWordProvider provider) { ExpressionInfo expressionInfo; switch (mode) { case ParamMode.Expression: { var relatedExpressionInfo = new RelatedExpressionInfo(); var strArry = paramStr.Replace(provider.ExpressionString, string.Empty).Split(provider.ExpressionSplitChar); relatedExpressionInfo.InvokeName = strArry[0]; if (strArry.Length == 2) { relatedExpressionInfo.ReturnTypeName = strArry[1]; } expressionInfo = relatedExpressionInfo; } break; case ParamMode.Func: { var funcExpressionInfo = new FuncExpressionInfo(); var strArry = paramStr.Replace(provider.FuncString, string.Empty).Split(provider.ExpressionSplitChar); funcExpressionInfo.Name = strArry[0]; if (strArry.Length > 1) { funcExpressionInfo.InvokeName = strArry[1]; } expressionInfo = funcExpressionInfo; } break; default: expressionInfo = new ExpressionInfo(); break; } expressionInfo.Mode = mode; expressionInfo.Str = paramStr; return(expressionInfo); }