public static CSharpExpressionEvaluation.EvaluateResult EvaluateStatement(string statement, object thisObject, bool evaluateValue, bool applyCasts, bool useDebugger) { List <Token> tokens = GetTokensOfStatement(statement); var variables = new Dictionary <string, CSharpExpressionEvaluation.Variable>() { { "this", new CSharpExpressionEvaluation.Variable() { Value = thisObject, Type = thisObject == null ? null : thisObject.GetType() } } }; var tracker = new EvaluationTracker(); CSharpExpressionEvaluation eval = new CSharpExpressionEvaluation(tokens, variables, Store, evaluateValue, tracker, useDebugger: useDebugger); //eval.EvaluateStatement(); eval.EvaluateExpression(); if (applyCasts) { eval.ApplyPendingCasts(); } return(new CSharpExpressionEvaluation.EvaluateResult() { Result = eval.CurrentValue, ResultType = eval.CurrentType }); //EvaluateStatement(tokens, thisObject, evaluateValue); }
public static KeyValuePair <Type, string> GetTypeOfCurrentStatement(string statement, int pos, object thisObject, bool applyCasts) { var beforeAndAfterPos = GetBeforeAndAfterPosition(statement, pos); var variables = new Dictionary <string, CSharpExpressionEvaluation.Variable>() { { "this", new CSharpExpressionEvaluation.Variable() { Value = thisObject, Type = thisObject == null ? null : thisObject.GetType() } } }; var leadingTokens = GetTokensOfStatement(beforeAndAfterPos.Key); var tracker = new EvaluationTracker(); //var tokens = GetTokensOfStatement(statement); //var tokenAtCurPos = GetTokenIndexFromCharIndex(statement, pos); //CSharpExpressionEvaluation eval = new CSharpExpressionEvaluation(leadingTokens, variables, Store, false, tracker); CSharpExpressionEvaluation eval = new CSharpExpressionEvaluation(leadingTokens, variables, Store, false, tracker); try { //eval.EvaluateStatement(); eval.EvaluateExpression(); if (applyCasts) { eval.ApplyPendingCasts(); } } catch (Exception) { } var result = new CSharpExpressionEvaluation.EvaluateResult() { Result = eval.CurrentValue, ResultType = eval.CurrentType }; //EvaluateResult result = EvaluateStatement(tokensAndAfter.Item1, thisObject, false); return(new KeyValuePair <Type, string>(result.ResultType, beforeAndAfterPos.Value)); }