public object FetchValue(TDataModel targetObject, IParsedExpression expression) { object subExprResult; if (expression.IsArrayExpression) { subExprResult = Invoke(targetObject, expression.LookUpKey, expression.ArrayIndicies); } else { subExprResult = Invoke(targetObject, expression.LookUpKey); } return(subExprResult); }
private static string OnTraversePrefixExpression(this IPrefixExpression prefix, Func <string, Operators, string, string> action) { Stack <string> stack = new Stack <string>(); IParsedExpression parsed = prefix.ParseExpression(); // Length of expression int l = parsed.Value.Length; // Reading from right to left for (int i = l - 1; i >= 0; i--) { char c = parsed.Value[i]; // Check whether the character is an operator if (c.IsOperator()) { // Check whether the character is operator of type Negation if (((char)Operators.Negation).Equals(c)) { // Get the previous result from the stack,calculate the next nandified result and put it in the stack string value = stack.Pop(); stack.Push(action(value, Operators.Negation, null)); } else { // Get the previous result from the stack,calculate the next nandified result and put it in the stack string value1 = stack.Pop(); string value2 = stack.Pop(); stack.Push(action(value1, (Operators)c, value2)); } } else { // Put the variable in the stack stack.Push($@"{c}"); } } return(stack.Pop()); }
private object FetchValueByReflection(TDataModel rootObject, IParsedExpression expression) { var currentType = mCachedType; var currentObject = (object)rootObject; for (var i = 0; i < expression.Tokens.Length; ++i) { var token = expression.Tokens[i]; var nextProp = GetPropertyByName(currentType, token.SubExpression); if (token.IsArrayExpression) { currentObject = (nextProp.GetValue(currentObject) as Array).GetValue(token.ArrayIndex); currentType = nextProp.PropertyType.GetElementType(); } else { currentObject = nextProp.GetValue(currentObject); currentType = nextProp.PropertyType; } } return(currentObject); }
public TOutput FetchValue <TOutput>(TDataModel targetObject, IParsedExpression expression) { var val = FetchValue(targetObject, expression); return((TOutput)val); }
public object FetchValue(TDataModel targetObject, IParsedExpression expression) { return(FetchValueByReflection(targetObject, expression)); }