Пример #1
0
        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));
            }
        }
        public double Evaluate(Dictionary <string, object> variables)
        {
            object listInstance = listExpr.GetInstance(variables);

            return(evaluator(listInstance, (int)indexExpr.Evaluate(variables)));
        }
        public double Evaluate(Dictionary <string, object> variables)
        {
            object instance = containingObject.GetInstance(variables);

            return(evaluator(instance));
        }