Guest User

Untitled

a guest
Oct 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. /// <summary>
  2. /// Finds users whose properties have certain values.
  3. /// </summary>
  4. /// <param name="propValues">Properties and values to look for.</param>
  5. /// <param name="props">Properties that will be requested by the engine from the returned users.</param>
  6. /// <returns>Enumerable with users whose properties match.</returns>
  7. public IEnumerable<IPrincipal> FindPrincipalsByPropertyValues(
  8. IList<PropertyValue> propValues,
  9. IList<PropertyName> props)
  10. {
  11. var user = new UserPrincipal(Context.GetPrincipalContext());
  12. user.Name = "*";
  13. foreach (PropertyValue v in propValues)
  14. {
  15. if (v.QualifiedName == PropertyName.DISPLAYNAME)
  16. {
  17. user.Name = "*" + v.Value + "*";
  18. }
  19. }
  20.  
  21. var searcher = new PrincipalSearcher(user);
  22. return searcher.FindAll().Select(u => new User((UserPrincipal)u, Context)).Cast<IPrincipal>();
  23. }
Add Comment
Please, Sign In to add comment