Có ai có thể cung cấp ví dụ về cách lặp qua System.DirectoryServices.PropertyCollection và xuất ra tên và giá trị thuộc tính không?Làm cách nào để lặp qua PropertyCollection
Tôi đang sử dụng C#.
@JaredPar - Thuộc tính sở hữu không có thuộc tính Tên/Giá trị. Nó có một PropertyNames và Values, gõ System.Collection.ICollection. Tôi không biết loại đối tượng basline tạo nên đối tượng PropertyCollection.
@JaredPar lần nữa - Ban đầu tôi đã gắn nhãn sai câu hỏi với loại sai. Đó là điều xấu của tôi.
Cập nhật: Dựa trên đầu vào Zhaph - Ben Duguid, tôi có thể phát triển mã sau đây.
using System.Collections;
using System.DirectoryServices;
public void DisplayValue(DirectoryEntry de)
{
if(de.Children != null)
{
foreach(DirectoryEntry child in de.Children)
{
PropertyCollection pc = child.Properties;
IDictionaryEnumerator ide = pc.GetEnumerator();
ide.Reset();
while(ide.MoveNext())
{
PropertyValueCollection pvc = ide.Entry.Value as PropertyValueCollection;
Console.WriteLine(string.Format("Name: {0}", ide.Entry.Key.ToString()));
Console.WriteLine(string.Format("Value: {0}", pvc.Value));
}
}
}
}
Tốt hơn bạn nên sử dụng chuyển đổi Implicit trong vòng lặp foreach. –