public string GetFilterText(Expression expression) { ProjectionExpression projection = this.Translate(expression); if (projection == null || projection.Searcher == null) { return(null); } return(LdapFilterFormatter.Format(projection.Searcher.Filter)); }
private DirectorySearcher CreateSearcher(DirectorySearcherExpression node) { if (node == null) { return(null); } DirectoryEntry searchRoot = node.SearchRoot; string filter = LdapFilterFormatter.Format(node.Filter); if (string.IsNullOrEmpty(filter)) { filter = null; } string[] propertiesToLoad = node.AttributesToLoad.Select(a => a.Name).ToArray(); SearchScope scope = node.Scope; SortOption sort = CreateSortOption(node.Sort); int? sizeLimit = null; if (node.Take != null) { var take = node.Take as ConstantExpression; if (take == null) { throw new NotSupportedException("Cannot have a take value of anything other than a constant."); } sizeLimit = (int)take.Value; // Have to add on the skip size, so we don't get too few results. var skip = node.Skip as ConstantExpression; if (skip != null) { sizeLimit += (int)skip.Value; } } var searcher = new DirectorySearcher(searchRoot, filter, propertiesToLoad, scope); if (sort != null) { searcher.Sort = sort; } if (sizeLimit.HasValue) { searcher.SizeLimit = sizeLimit.Value; } return(searcher); }