public Func <Dictionary <string, object>, T> GetItemGetter <T>(int index) { IExpression itemExpr = Expressions[index]; Type itemType = typeof(T); if (ReflectionHelper.IsNumber(itemType)) { INumericExpression numericExpr = (INumericExpression)itemExpr; Func <double, T> converter = ReflectionHelper.GenerateFromDoubleConverter <T>(); return(variables => converter(numericExpr.Evaluate(variables))); } else if (itemType == typeof(bool)) { MethodInfo generateGetterMethod = GetType() .GetMethod("GetBooleanItemGetter", BindingFlags.NonPublic | BindingFlags.Static); Func <IBooleanExpression, Func <Dictionary <string, object>, T> > generateGetterDelegate = ReflectionHelper.CreateDelegate <IBooleanExpression, Func <Dictionary <string, object>, T> >(generateGetterMethod); IBooleanExpression booleanExpr = (IBooleanExpression)itemExpr; return(generateGetterDelegate(booleanExpr)); } else if (itemType == typeof(string)) { MethodInfo generateGetterMethod = GetType() .GetMethod("GetStringItemGetter", BindingFlags.NonPublic | BindingFlags.Static); Func <IStringExpression, Func <Dictionary <string, object>, T> > generateGetterDelegate = ReflectionHelper.CreateDelegate <IStringExpression, Func <Dictionary <string, object>, T> >(generateGetterMethod); IStringExpression booleanExpr = (IStringExpression)itemExpr; return(generateGetterDelegate(booleanExpr)); } else { IObjectExpression objectExpr = (IObjectExpression)itemExpr; return(variables => (T)objectExpr.GetInstance(variables)); } }
private static Func <Dictionary <string, object>, string> GetStringItemGetter(IStringExpression stringExpr) { return(variables => stringExpr.Evaluate(variables)); }