以下是一个编辑ADPropertyValueCollection的示例代码:
using System.Collections.Generic;
using System.DirectoryServices;
public void EditADPropertyValueCollection(IList values)
{
// 创建一个新的ADPropertyValueCollection对象
ADPropertyValueCollection propertyValueCollection = new ADPropertyValueCollection();
// 将传入的值添加到ADPropertyValueCollection中
foreach (string value in values)
{
propertyValueCollection.Add(value);
}
// 编辑ADPropertyValueCollection中的值
propertyValueCollection.Remove("OldValue");
propertyValueCollection.Add("NewValue");
// 最后,你可以将ADPropertyValueCollection重新赋值给相应的属性
// 例如,如果你要编辑的是用户对象的"memberOf"属性,可以这样做:
DirectoryEntry entry = new DirectoryEntry("LDAP://CN=User,DC=Domain,DC=com");
entry.Properties["memberOf"].Value = propertyValueCollection;
// 提交更改
entry.CommitChanges();
}
在上述代码中,我们首先创建了一个新的ADPropertyValueCollection对象,然后将传入的值添加到ADPropertyValueCollection中。接下来,我们使用Remove方法从ADPropertyValueCollection中删除了一个旧值,并使用Add方法添加了一个新值。最后,我们将修改后的ADPropertyValueCollection赋值给相应的属性,并通过调用CommitChanges方法提交更改。