2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.DirectoryServices / System.DirectoryServices / SearchResult.cs
blobc9abd5b08ad19e4448c5175dfdd0cb5d10f292a5
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc., www.novell.com
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
25 // System.DirectoryServices.SearchResult.cs
27 // Author:
28 // Sunil Kumar (sunilk@novell.com)
30 // (C) Novell Inc.
33 using System.ComponentModel;
34 using Novell.Directory.Ldap;
35 using System.Collections.Specialized;
37 namespace System.DirectoryServices
40 /// <summary>
41 ///Encapsulates a node or object in the Ldap Directory hierarchy.
42 /// </summary>
43 public class SearchResult
46 private string _Path=null;
47 private ResultPropertyCollection _Properties=null;
48 private DirectoryEntry _Entry=null;
49 private StringCollection _PropsToLoad=null;
50 private bool ispropnull=true;
51 private PropertyCollection _Rproperties = null;
53 internal PropertyCollection Rproperties
55 get
57 return _Rproperties;
61 private void InitBlock()
63 _Properties=null;
64 _Entry=null;
65 _PropsToLoad=null;
66 ispropnull=true;
67 _Rproperties=null;
70 internal StringCollection PropsToLoad
72 get
74 if( _PropsToLoad != null )
76 return _PropsToLoad;
78 else
79 return null;
82 /// <summary>
83 /// Gets a ResultPropertyCollection of properties set on this object.
84 /// </summary>
85 /// <value>
86 /// A ResultPropertyCollection of properties set on this object.
87 /// </value>
88 /// <remarks>
89 /// This collection only contains properties that were explicitly
90 /// requested through DirectorySearcher.PropertiesToLoad.
91 /// </remarks>
92 public ResultPropertyCollection Properties
94 get
96 if ( ispropnull )
98 _Properties= new ResultPropertyCollection();
99 System.Collections.IDictionaryEnumerator id =
100 Rproperties.GetEnumerator();
101 // _Entry.Properties.GetEnumerator();
102 while(id.MoveNext())
104 string attribute=(string)id.Key;
105 ResultPropertyValueCollection rpVal=
106 new ResultPropertyValueCollection();
107 if(Rproperties[attribute].Count==1)
109 String val = (String)Rproperties[attribute].Value;
110 rpVal.Add(val);
112 else if (Rproperties[attribute].Count > 1)
114 Object[] vals=(Object [])Rproperties[attribute].Value;
115 // String[] aStrVals= new String[_Entry.Properties[attribute].Count];
116 rpVal.AddRange(vals);
118 _Properties.Add(attribute,rpVal);
120 ispropnull=false;
122 return _Properties;
126 internal SearchResult(DirectoryEntry entry)
128 InitBlock();
129 _Entry = entry;
130 _Path = entry.Path;
133 internal SearchResult(DirectoryEntry entry, PropertyCollection props)
135 InitBlock();
136 _Entry = entry;
137 _Path = entry.Path;
138 _Rproperties = props;
140 /// <summary>
141 /// Gets the path for this SearchResult.
142 /// </summary>
143 /// <value>
144 /// The path of this SearchResult.
145 /// </value>
146 /// <remarks>
147 /// The Path property uniquely identifies this entry in the Active
148 /// Directory hierarchy. The entry can always be retrieved using this
149 /// path
150 /// </remarks>
151 public string Path
155 return _Path;
159 /// <summary>
160 /// Retrieves the DirectoryEntry that corresponds to the SearchResult,
161 /// from the Active Directory hierarchy.
162 /// </summary>
163 /// <returns>
164 /// The DirectoryEntry that corresponds to the SearchResult
165 /// </returns>
166 /// <remarks>
167 /// Use GetDirectoryEntry when you want to look at the live entry
168 /// instead of the entry returned through DirectorySearcher, or when
169 /// you want to invoke a method on the object that was returned.
170 /// </remarks>
171 public DirectoryEntry GetDirectoryEntry()
173 return _Entry;