Skip to content

The core, platform-agnostic transpiler and parser behind Linq2Ldap.

License

Notifications You must be signed in to change notification settings

cdibbs/linq2ldap.core

Repository files navigation

LINQ2LDAP MIT License

Build status codecov Code of Conduct

Linq2Ldap.Core

This is the core compiler and parser behind the Linq2Ldap.* NuGet libraries. It can compile C# LINQ Expressions into RFC 4515 (or 2254/1960) LDAP filter strings, and it can parse an LDAP filter into a LINQ Expression.

If you only want to use the filter compiler with no additional abstraction, you can do this:

    // Goal: produce this filter string from a LINQ Expression
    //     filter = "(&(samaccountname=will*)(&(email=*uiowa*)(!(customprop=123))))";
    
    string filter = new LdapFilterCompiler().Compile(
        (MyUserModel u)
                    => u.SamAccountName.StartsWith("will")
                    && u.Email.Contains("uiowa")
                    && u["customprop"] != "123");

    var searcher = new DirectorySearcher();
    searcher.Filter = filter;

    // -- or --

    var searchReq = new SearchRequest(targetOu, filter, /* ... */);

Also supported query examples:

(MyUserModel u) => u.Title.Matches("univ*of*iowa"); // (title=univ*of*iowa)
(MyUserModel u) => u.Email.EndsWith("@gmail.com"); // (mail=*@gmail.com)
(MyUserModel u) => u["acustomproperty"].Contains("some val"); // (acustomproperty=*some val*)
(MyUserModel u) => u.Has("somekey"); // (somekey=*)

For more information about models and properties, please visit the Wiki.

Additional abstractions

Wrappers around some of the search functionality in System.DirectoryServices and System.DirectoryServices.Protocols can be found, here. These include, for example, LinqDirectorySearcher<T> and LinqSearchRequest<T>, respectively.

Contributing

Coin Address
Ethereum 0xfCdA80Be00F8907FfcD227683D9D96f7C47eC67f
Bitcoin 33pypS6oRmgmvMwAnX5rpJAaxnqScxSALS