Traverse an expression tree and extract parameters

 

I think as you've said that using ExpressionVisitor works out to be a good approach. You don't need to implement all the Visit... methods as they already have a default implementation. From what I understood what you want is to find all property accesses of a certain type inside a lambda function

public class MemberAccessVisitor : ExpressionVisitor
{
private readonly Type declaringType;
private IList<string> propertyNames = new List<string>(); public MemberAccessVisitor(Type declaringType)
{
this.declaringType = declaringType;
} public IEnumerable<string> PropertyNames { get { return propertyNames; } } public override Expression Visit(Expression expr)
{
if (expr != null && expr.NodeType == ExpressionType.MemberAccess)
{
var memberExpr = (MemberExpression)expr;
if (memberExpr.Member.DeclaringType == declaringType)
{
propertyNames.Add(memberExpr.Member.Name);
}
} return base.Visit(expr);
}
}

This could be further improved to what you want by checking the member is a property and also to get PropertyInfo rather than strings

It could be used as follows:

var visitor = new MemberAccessVisitor(typeof(TSource));

visitor.Visit(memberMap);

var propertyNames = visitor.PropertyNames;

最新文章

  1. 高性能网站架构设计之缓存篇(1)- Redis的安装与使用
  2. NBUT 1010 魔法少女(DP)
  3. 帮初学者改代码——playerc之“练习:求完数问题”(下)
  4. E2 2014.08.05 更新日志
  5. 集合框架学习之Guava Collection
  6. ubuntu find方法
  7. 重写OnPaint事件对窗体重绘(显示gif动画) 实例2
  8. 数据泵导出/导入Expdp/impdp
  9. 浏览器 HTTP 缓存原理分析
  10. echarts 某省下钻某市地图
  11. JSP慕课网阶段用户登录小例子(不用数据库)
  12. 基于MySQL + Node.js + Leaflet的离线地图展示,支持百度、谷歌、高德、腾讯地图
  13. Matplotlib初体验
  14. The MySQL Server
  15. Oracle11g温习-第十六章:用户管理
  16. docker 简单入门(一)
  17. [深入浅出iOS库]之图形库CorePlot
  18. 安卓开发之不通过USB数据线调试的方法
  19. Android逆向之旅---静态方式分析破解视频编辑应用「Vue」水印问题
  20. 英雄pk理解面向对象中的this指针概念

热门文章

  1. 如何在SAP Cloud Platform ABAP编程环境里创建一个employee
  2. MySQL数据库的事物隔离级别
  3. Redhat下Oracle 12c单节点安装
  4. nginx简单学习
  5. 【Low版】HAUT - OJ - Contest1035 - 2017届新生周赛(六)题解
  6. 使用Restful风格中的post使用过遇到前端数据传送不到后端
  7. Union-Find(并查集): Dynamic Connectivity 问题
  8. C# 4.0 新特性(.NET Framework 4.0 与 Visual Studio 2010 )
  9. EPL II 编程打印
  10. 通过命令行运行java出现&quot;错误: 找不到或无法加载主类 &quot;解决办法