PrincipalCollection.Contains PrincipalCollection.Contains PrincipalCollection.Contains PrincipalCollection.Contains Method

Definition

Returns a value that indicates whether the specified Principal is a member of the PrincipalCollection. The Principal can be specified in the same manner as in the Add methods.

Overloads

Contains(ComputerPrincipal) Contains(ComputerPrincipal) Contains(ComputerPrincipal) Contains(ComputerPrincipal)

Returns a value indicating whether the collection contains the specified ComputerPrincipal object.

Contains(GroupPrincipal) Contains(GroupPrincipal) Contains(GroupPrincipal) Contains(GroupPrincipal)

Returns a value indicating whether the collection contains the specified GroupPrincipal object.

Contains(Principal) Contains(Principal) Contains(Principal)

Returns a value indicating whether the collection contains the specified Principal object.

Contains(UserPrincipal) Contains(UserPrincipal) Contains(UserPrincipal) Contains(UserPrincipal)

Returns a value indicating whether the collection contains the specified UserPrincipal object.

Contains(PrincipalContext, IdentityType, String) Contains(PrincipalContext, IdentityType, String) Contains(PrincipalContext, IdentityType, String)

Returns a value indicating whether the Principal object matching the identityType/identityValue pair is in the collection.

Remarks

As with Add, and Remove there are four overloads to this function, but they all do the same thing. The extra overloads are only implemented to improve usability, so that developers using IntelliSense see overloads that take a UserPrincipal, GroupPrincipal, or ComputerPrincipal object. Calling any one of the User, Group, or Computer overloads is exactly equivalent to calling the Principal overload.

Contains(ComputerPrincipal) Contains(ComputerPrincipal) Contains(ComputerPrincipal) Contains(ComputerPrincipal)

Returns a value indicating whether the collection contains the specified ComputerPrincipal object.

public:
 bool Contains(System::DirectoryServices::AccountManagement::ComputerPrincipal ^ computer);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
member this.Contains : System.DirectoryServices.AccountManagement.ComputerPrincipal -> bool
Public Function Contains (computer As ComputerPrincipal) As Boolean

Parameters

Returns

true if the collection contains the specified object; otherwise, false.

Contains(GroupPrincipal) Contains(GroupPrincipal) Contains(GroupPrincipal) Contains(GroupPrincipal)

Returns a value indicating whether the collection contains the specified GroupPrincipal object.

public:
 bool Contains(System::DirectoryServices::AccountManagement::GroupPrincipal ^ group);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.GroupPrincipal group);
member this.Contains : System.DirectoryServices.AccountManagement.GroupPrincipal -> bool
Public Function Contains (group As GroupPrincipal) As Boolean

Parameters

Returns

true if the collection contains the specified object; otherwise, false.

Contains(Principal) Contains(Principal) Contains(Principal)

Returns a value indicating whether the collection contains the specified Principal object.

public:
 virtual bool Contains(System::DirectoryServices::AccountManagement::Principal ^ principal);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.Principal principal);
abstract member Contains : System.DirectoryServices.AccountManagement.Principal -> bool
override this.Contains : System.DirectoryServices.AccountManagement.Principal -> bool

Parameters

Returns

true if the collection contains the specified object; otherwise, false.

Implements

Contains(UserPrincipal) Contains(UserPrincipal) Contains(UserPrincipal) Contains(UserPrincipal)

Returns a value indicating whether the collection contains the specified UserPrincipal object.

public:
 bool Contains(System::DirectoryServices::AccountManagement::UserPrincipal ^ user);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.UserPrincipal user);
member this.Contains : System.DirectoryServices.AccountManagement.UserPrincipal -> bool
Public Function Contains (user As UserPrincipal) As Boolean

Parameters

Returns

true if the collection contains the specified object; otherwise, false.

Contains(PrincipalContext, IdentityType, String) Contains(PrincipalContext, IdentityType, String) Contains(PrincipalContext, IdentityType, String)

Returns a value indicating whether the Principal object matching the identityType/identityValue pair is in the collection.

public:
 bool Contains(System::DirectoryServices::AccountManagement::PrincipalContext ^ context, System::DirectoryServices::AccountManagement::IdentityType identityType, System::String ^ identityValue);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
member this.Contains : System.DirectoryServices.AccountManagement.PrincipalContext * System.DirectoryServices.AccountManagement.IdentityType * string -> bool

Parameters

identityType
IdentityType IdentityType IdentityType IdentityType

An IdentityType object that specifies the format of identityValue

identityValue
String String String String

A string that identifies the principal, in the format specified by identityType

Returns

true if an object matching the identityType/identityValue pair is in the collection; otherwise, false.

Remarks

This function can throw the following exceptions:

Exception Description
MultipleMatchesException There are multiple principals matching these parameters.
ArgumentException The identityType parameter cannot be empty.

Applies to