PropertiesVisitor.cs 988 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using System.Reflection;
  5. namespace Masuit.Tools.Mapping.Visitor
  6. {
  7. internal class PropertiesVisitor : ExpressionVisitor
  8. {
  9. private readonly List<PropertyInfo> _propertiesOfExpression;
  10. private readonly Type _typeReference;
  11. internal PropertiesVisitor(Type typeReference)
  12. {
  13. _typeReference = typeReference;
  14. _propertiesOfExpression = new List<PropertyInfo>();
  15. }
  16. protected override Expression VisitMember(MemberExpression node)
  17. {
  18. if (_typeReference == node.Member.DeclaringType)
  19. {
  20. _propertiesOfExpression.Add(node.Member as PropertyInfo);
  21. }
  22. return base.VisitMember(node);
  23. }
  24. internal List<PropertyInfo> GetProperties(Expression expression)
  25. {
  26. Visit(expression);
  27. return _propertiesOfExpression;
  28. }
  29. }
  30. }