Beispiel #1
0
        public static T Evaluate <T>(DataElement data, Row row, List <Index> usedIndexes, string formula, int columnIndex = 0)
        {
            IEnumerable <Index> actualUsedIndexes = usedIndexes.Where(i => data.HasColumn(i));
            string     expressionText             = formula.ToLower();
            Expression expression = new Expression(expressionText);

            foreach (Index usedColumnIndex in actualUsedIndexes)
            {
                object dataItemValue = null;
                string name          = usedColumnIndex.Name;
                if (usedColumnIndex.Number.HasValue)
                {
                    dataItemValue = row[usedColumnIndex.Number.Value];
                    name          = "c#" + usedColumnIndex.Number.Value;
                }
                else
                {
                    dataItemValue = row[usedColumnIndex.Name];
                }
                AddParameter(expression, name.ToLower(), dataItemValue);
            }
            if (expressionText.Contains("[value]"))
            {
                AddParameter(expression, "value", row[columnIndex]);
            }
            T result = (T)expression.Evaluate();

            return(result);
        }