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. c# 定制Equals()

  2. Python中type()详解:动态创建类

    众所周知: type()函数可以查看变量的类型: 先看一个简单的列子来看一下type查看变量类型 class Animal(): pass a=Animal() print(type(a)) prin ...

  3. 【DevOps】在CentOS中安装Rancher2,并配置kubernetes集群

    准备 一台CentOS主机,安装DockerCE,用于安装Rancher2 一台CentOS主机,安装DockerCE,用于安装kubernetes集群管理主机 多台CentOS主机,安装Docker ...

  4. 更改和配置本地yum源

    查看yum 存放位置 [root@web01 yum.repos.d]# ll /etc/yum.repos.d/ total -rw-r--r--. root root Jun CentOS-Bas ...

  5. Gym - 102012H Rikka with A Long Colour Palette N线段K色贪心染色

    给你数轴上的N条线段和K种颜色 K和N1e5 要你把这N条线段染色 使得有K种不同颜色的线段长度最长 首先很容易想到被至少K段线段覆盖的区间是一定有贡献的 接下来就是怎么染色的问题 我们把这N个区间的 ...

  6. Vmware Pro 14报错:无法连接 MKS: 套接字连接尝试次数太多;正在放弃。

    软件环境: 虚拟机软件:VMware Pro 14 母机操作系统:win7 客户机操作系统:CentOS 7     问题详情: 报错:无法连接 MKS: 套接字连接尝试次数太多:正在放弃.     ...

  7. JVM 平台上的 Scheme 语言实现 JSchemeMin

    JSchemeMin 是一个JVM平台上的Scheme语言实现. 作为R7RS的实现,JSchemeMin支持Scheme的所有标准特性,包括头等公民地位的过程.尾递归优化.继续.用户定义记录.库(包 ...

  8. 从linq的一次优化实践看group by+Min/Max()处理数据后需要额外的其他列问题

    问题简化如下: 假设有第三方的表结构如下(可能会出现完全相同的重复数据): 1.写SQL语句,查询每个学生的,userid.最高分.最高分的科目.最高分的考点.最低分.最低分科目.最低分考点(分数相同 ...

  9. sql server 变量和select 赋值的联合使用demo

    ) ) select @cltcode=cltcode,@brand=brand from prosamplehd CREATE table #t ( cltcode ), brand ) ) INS ...

  10. 16 | “order by”是怎么工作的?

    在你开发应用的时候,一定会经常碰到需要根据指定的字段排序来显示结果的需求.还是以我们前面举例用过的市民表为例,假设你要查询城市是“杭州”的所有人名字,并且按照姓名排序返回前1000个人的姓名.年龄. ...