protected override Expression VisitMember(MemberExpression node) { if (_flag) { var propertyPath = new PropertyPathVisitor(node, false).GetPropertyPath(); var ifNotContainPath = Properties.FirstOrDefault(s => s.StartsWith(propertyPath)) == null; if (ifNotContainPath) { if (Properties.Count > 0) { var element = Properties.ElementAt(Properties.Count - 1); if (_underlyingRootType != null && _underlyingRootType.IsValidPropertyPath(element) == false) { propertyPath = $"{propertyPath}{CollectionSuffix}.{element}"; Properties.Remove(element); } //else if (_underlyingRootType != null && _underlyingRootType.IsValidPropertyPath(propertyPath) == false) //{ // //throw new NotSupportedException(string.Format("This expression is not supported: {0}", UnderlyingExpression ?? node)); //} } Properties.Add(propertyPath); } } return(base.VisitMember(node)); }
public static HashSet <string> GetAllPropertiesPaths(this Expression expression, string collectionSuffix = null) { if (expression == null) { return(null); } var visitor = new PropertyPathVisitor { CollectionSuffix = collectionSuffix }; visitor.Visit(expression); return(visitor.Properties); }