Customize DataColumn.Expression handling in C#

喜夏-厌秋 提交于 2020-01-23 02:32:47

问题


I would like to change behavior of DataColumn.Expression so that when I write:

DataColumn.Expression = "MyMethod(Price)"

It will call MyMethod, pass value from Price column into it and display evaluated value.

How can I acomplish this?


回答1:


Not possible. The expression parser behind the Expression property is simple and not extensible. Making arbitrary function calls is not one of its capabilities. There are several ways to work around this, especially ones that don't require an expensive reflection lookup. Consider the DataTable.RowChanged event for example.




回答2:


A way around this is to make your function a calculated field like in databases and spredsheets. It is possible to make advanced calculated fields. You need to rewrite your function to an expression and then use [Price] to refer to the source column. As I understand your question it makes it possible to do what you intend. The syntax for expression can be found here.

I know this is a late answer to the question but it might help others looking into how to do this.



来源:https://stackoverflow.com/questions/1707897/customize-datacolumn-expression-handling-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!