I want to extend the GroupPrincipal
class to handle some custom properties:
using System.DirectoryServices.AccountManagement;
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("group")]
public class MyGroupPrincipal : GroupPrincipal {
// ...
}
How could I override the Members
property for MyGroupPrincipal
so that if it has a member that is a group an instance of MyGroupPrincipal
and not of GroupPrincipal
is returned? I would like to write e.g.
MyGroupPrincipal group = GetGroup();
foreach (var m in group.Members) {
if (m is MyGroupPrincipal) { // always fails: m is a normal GroupPrincipal
// do something
}
}