This question is locked. New answers and comments are not allowed.
If I have a custom aggregate function like this:
public static decimal Expression<TSource>(IEnumerable<TSource> source, Func<TSource, decimal> selector)
how can I get the calling property or column name from inside the function? The source and the selector do not expose the property or column name for which this function is called. Would really appreciate if somebody can help me in anyway.
Some background on why I need this:
I use the lightweight datatable to bind to the grid. The datatable is generated based on some SQL statements. The SQL statements can differ based on some logic, meaning the datatable will look differently based on the SQL statements executed. The actual working behind the scenes are a bit more complicated, but this explanation should give the scenario. The columns retrieved also have some extra metadata. One of which is an expression like: [Sales] - [Cost] / [Cost] where the column names are in brackets.I can the have this expression on a column called [GP%]. In my aggregate function I like to get this expression metadata when the [GP%] property/column function is executed. Based on the expression I can then call some expression evaluator to calculate the formula. In the function I will just do sum(Sales), sum(Cost) and pass this to the expression evaluator to the calculation for the GP%.and return the result.
Without knowing the calling property I will not be able to get this expression metadata.
public static decimal Expression<TSource>(IEnumerable<TSource> source, Func<TSource, decimal> selector)
how can I get the calling property or column name from inside the function? The source and the selector do not expose the property or column name for which this function is called. Would really appreciate if somebody can help me in anyway.
Some background on why I need this:
I use the lightweight datatable to bind to the grid. The datatable is generated based on some SQL statements. The SQL statements can differ based on some logic, meaning the datatable will look differently based on the SQL statements executed. The actual working behind the scenes are a bit more complicated, but this explanation should give the scenario. The columns retrieved also have some extra metadata. One of which is an expression like: [Sales] - [Cost] / [Cost] where the column names are in brackets.I can the have this expression on a column called [GP%]. In my aggregate function I like to get this expression metadata when the [GP%] property/column function is executed. Based on the expression I can then call some expression evaluator to calculate the formula. In the function I will just do sum(Sales), sum(Cost) and pass this to the expression evaluator to the calculation for the GP%.and return the result.
Without knowing the calling property I will not be able to get this expression metadata.
