/
SearchResult.cs
49 lines (43 loc) · 1.95 KB
/
SearchResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Net;
namespace System.DirectoryServices
{
/// <devdoc>
/// Encapsulates a node in the Active Directory hierarchy
/// that is returned during a search through <see cref='System.DirectoryServices.DirectorySearcher'/>.
/// </devdoc>
public class SearchResult
{
private readonly NetworkCredential? _parentCredentials;
private readonly AuthenticationTypes _parentAuthenticationType;
internal SearchResult(NetworkCredential? parentCredentials, AuthenticationTypes parentAuthenticationType)
{
_parentCredentials = parentCredentials;
_parentAuthenticationType = parentAuthenticationType;
}
/// <devdoc>
/// Retrieves the <see cref='System.DirectoryServices.DirectoryEntry'/> that corresponds to the <see cref='System.DirectoryServices.SearchResult'/>, from the Active Directory
/// hierarchy.
/// </devdoc>
public DirectoryEntry GetDirectoryEntry()
{
if (_parentCredentials != null)
return new DirectoryEntry(Path, true, _parentCredentials.UserName, _parentCredentials.Password, _parentAuthenticationType);
else
{
DirectoryEntry newEntry = new DirectoryEntry(Path, true, null, null, _parentAuthenticationType);
return newEntry;
}
}
/// <devdoc>
/// Gets the path for this <see cref='System.DirectoryServices.SearchResult'/>.
/// </devdoc>
public string Path => (string)Properties["ADsPath"][0]!;
/// <devdoc>
/// Gets a <see cref='System.DirectoryServices.ResultPropertyCollection'/>
/// of properties set on this object.
/// </devdoc>
public ResultPropertyCollection Properties { get; } = new ResultPropertyCollection();
}
}