Get Argument Values From Linq Expression

If you even find yourself unpacking an expression in C#, you might find this useful. I found myself in need of obtaining a list of argument values from within an Expression<func> expression that sometimes had chained method calls. For example, I needed to be able to get the arguments from all of the following…

SomeMethod(() => getInformation.ForCustomer(CustomerId));

SomeMethod(() => MyFactory.GetInformation().ForCustomer(CustomerId));

SomeMethod(() => MyFactory.GetInformation().ForCustomer(CustomerId).ToList());

In the end, I created a couple of extension methods to help. One converts an expression into a MethodCallExpression (if that is a valid conversion), which is a type that has arguments. The second recursively searches for the arguments.

Get Argument Values From Linq Expression的更多相关文章

  1. [Linq Expression]练习自己写绑定

    源代码:TypeMapper.zip 背景 项目中,我们会经常用到各种赋值语句,比如把模型的属性赋值给UI,把视图模型的属性拷贝给Entity.如果模型属性太多,赋值也会变成苦力活.所以,框架编程的思 ...

  2. ling join 报错The specified LINQ expression contains references to queries that are associated with different cont

    The specified LINQ expression contains references to queries that are associated with different cont ...

  3. C# ORM中Dto Linq Expression 和 数据库Model Linq Expression之间的转换

    今天在百度知道中看到一个问题,研究了一会便回答了: http://zhidao.baidu.com/question/920461189016484459.html 如何使dto linq 表达式转换 ...

  4. diff/merge configuration in Team Foundation - common Command and Argument values - MSDN Blogs

    One of the extensibility points we have in Team Foundation V1 is that you can configure any other di ...

  5. C# [LINQ] Linq Expression 获取多格式文件

    using System; using System.IO; using System.Linq; using System.Linq.Expressions; internal static str ...

  6. 查看LINQ Expression編譯後的SQL語法(转)

    在用了LINQ語法之後的一個月,我幾乎把SQL語法全部拋到腦後了,不過 LINQ好用歸好用,但是實際上操作資料庫的還是SQL語法,如果不知道LINQ語法 編譯過後產生怎樣的SQL語法,一不小心效能就會 ...

  7. The specified LINQ expression contains references to queries that are associated with different contexts

    今天在改写架构的时候,遇到这么个错误.当时单从字面意思,看上去错误是由join的两个不同的表来源不一致引起的. 其中的videoResult和deerpenList均来自与同一个edmx文件,所以两个 ...

  8. Expression 表达式动态生成

    http://blog.csdn.net/duan1311/article/details/51769119 以上是拼装和调用GroupBy的方法,是不是很简单,只要传入分组列与合计列就OK了! 下面 ...

  9. Expression Tree Basics 表达式树原理

    variable point to code variable expression tree data structure lamda expression anonymous function 原 ...

随机推荐

  1. bootstrap table分页limit计算pageIndex和pageSize

    由于bootstrap table的js无法直接获取pageSize和pageIndex的值,只能通过limit进行计算.

  2. windows上安装python虚拟环境

    一.windows上安装python虚拟环境 1.安装pip install virtualenvvirtualenv --version 2.新建一个python虚拟环境virtual_env_01 ...

  3. 改变说明文档显示位置wrap

    装饰器会改变文档的显示位置 例子1:使用wrap前,输出内函数中的说明文档 def check(fun): """检查权限的装饰器""" d ...

  4. 软件自带依赖库还是共享对象库/为什么linux发行版之间不能有一个统一的二进制软件包标准

    接前文:Linux软件包(源码包和二进制包)及其区别和特点 在前文,我们知道了linux软件包分为源码包和二进制包两种方式,而不同的发行版之间又有着自己的二进制打包格式. 首先,软件运行依赖着各种各样 ...

  5. c# 处理串行化对象的版本变化

  6. 2-3 查找树及其Java实现

    2-3 查找树 定义(来源:wiki) 查找 插入 2-3 查找树 定义(来源:wiki) 2–3树是一种树型数据结构,内部节点(存在子节点的节点)要么有2个孩子和1个数据元素,要么有3个孩子和2个数 ...

  7. querySelector和getElementById方法的区别

    一.querySelector() 的定义 querySelector() 方法选择指定 CSS 选择器的第一个元素 querySelectorAll() 方法选择指定的所有元素 二.与 getEle ...

  8. vue---父调子 $refs (把父组件的数据传给子组件)

    ps:App.vue 父组件 Hello.vue 子组件  App.vue  : <template> <div id="app"> <input t ...

  9. 利用os模块求一个文件夹的大小。

    一.递归方法 def size(path): #给定一个初始的文件夹路径 num = 0 list_name = os.listdir(path) #利用os模块方法,以列表的形式获得该文件夹下面的所 ...

  10. Robot Framework--Scalar变量

    一.变量赋值 1)Set赋值 通常使用Set Variable关键字对变量进行赋值,其他Set相关的带Variable的关键字也可以进行赋值 赋值的时候,变量后面写不写『=』都可以,如下: 如果${v ...