Skip to content

Filter Methods

Chris Dibbern edited this page Nov 12, 2019 · 5 revisions

bool Any()

Shorthand for .Matches("*") or .StartsWith(String.Empty).

(Model m) => m.Email.Any();    // (email=*)
(Model m) => m["email"].Any(); // (email=*)

bool Contains(string substr)

bool EndsWith(string substr)

bool StartsWith(string substr)

These methods check whether the LDAP property contains a value that contains the given substring. They are the familiar special cases of Matches, below. Depending on how you setup your models, these methods can each refer to one of several different methods, including the built-in string extension methods.

                                               // Compiled results:
(Model m) => m.SomeProp.Contains("something"); // (someprop=*something*)
(Model m) => m.Mail.EndsWith("@example.com");  // (mail=*@example.com)
(Model m) => m.Name.StartsWith("will");        // (name=will*)
(Model m) => m["name"].StartsWith("will");     // (name=will*)

bool Matches(this string val, string expr)

Emulates an LDAP match. The explicit parameter, expr, can be any string that would be used on the right-hand side of an LDAP = filter.

                                                // Compiled results:
(Model m) => m.SomeProp.Matches("*");           // (someprop=*)
(Model m) => m.Phone.Matches("555-*");          // (phone=555-*), same as .BeginsWith("555-")
(Model m) => m.Alphabet.Matches("abc*jkl*xyz"); // (alphabet=abc*jkl*xyz)

To provide for custom types, you can also subclass one of the BaseLdap* classes which have the following overloads available:

bool Matches<T, U>(this BaseLdapManyType<T, U> source, string pattern)
   where T: IComparable
   where U: class, IConverter<List<T>>;
bool Matches<T>(this BaseLdapType<T, U> source, string pattern)
   where T: IComparable
   where U: class, IConverter<T>;

The author of this library apologizes for implementing this as an extension method. However, in this case, it is justified, since we want the method to work even when the instance is null (say, for an existence check).

bool IEntry.Has(string propName)

(Model m) => m.Has("somecustomprop");

// Compiled result: (somecustomprop=*)

This is synonymous with .Matches("*") and is an existence check.

bool Approx(this string source, string pattern)

Performs an LDAP ~= approximate match.

(Model m) => m.Mail.Approx("a value*of some kind");

// Compiled result: (mail~=a value*of some kind)

To provide for custom types, you can also subclass one of the BaseLdap* classes which have the following overloads available:

bool Approx<T, U>(this BaseLdapManyType<T, U> source, string pattern)
            where T: IComparable
            where U: class, IConverter<List<T>>;
bool Approx<T>(this BaseLdapType<T> source, string pattern)
            where T: IComparable
            where U: class, IConverter<T>