Extending GroupPrincipal and Members property
Posted
by Paolo Tedesco
on Stack Overflow
See other posts from Stack Overflow
or by Paolo Tedesco
Published on 2010-04-19T15:47:18Z
Indexed on
2010/05/09
4:08 UTC
Read the original article
Hit count: 886
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
}
}
© Stack Overflow or respective owner