Skip to content

Queryable

Julien Amsellem edited this page Sep 30, 2017 · 2 revisions

IQueryable

Intro

Like IQuery you get an IQueryable object through EverythingNet library, there is no public implementation. Suppose you want to search for all files and folders that contains the string "temp" (like a temporary file).

IEverything everything = new Everything();
var results = everything.Search().Name.Contains("temp");

I did used var on purpose because we'll see later how to use the results. Anyway at this point the query has not been executed yet because it's only executed when enumerating the results (ok, now you know that it's an IEnumerable<T>).

Most of the time you'll want to know the number of results found by the query, so there's also a Count property which will trigger the query execution on first call.

Enumerate the results

Let's see how to loop through the results:

IEverything everything = new Everything();
var results = everything.Search().Name.Contains("temp");
foreach(var result in results)
{
  Console.WriteLine(result);
}

Logical operator

In some more complex scenario you'll want to combine multiple queries with logical operators. Right now you can combine queries with Or and And logical operators:

IEverything everything = new Everything();
var results = everything.Search()
  .Name
  .Contains("temp")
  .And
  .Size
  .GreaterThan(1, SizeUnit.Mb);

You'll notice how I have formatted the code above to make it more readable (this is quite standard when dealing with fluent APIs).
I hope it's obvious for everybody, but the purpose of the query above is to find files whose name contains "temp" and whose size is greater than 1Mb.

Specific search queries


<< Previous | Next >>

Clone this wiki locally