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)

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

Contains(GroupPrincipal)

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

Contains(Principal)

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

Contains(UserPrincipal)

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

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)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

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

public:
 bool Contains(System::DirectoryServices::AccountManagement::ComputerPrincipal ^ computer);
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
[<System.Security.SecurityCritical>]
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.

Attributes

Applies to

Contains(GroupPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

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

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

Parameters

group
GroupPrincipal

A GroupPrincipal object.

Returns

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

Attributes

Applies to

Contains(Principal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

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

public:
 virtual bool Contains(System::DirectoryServices::AccountManagement::Principal ^ principal);
public 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
[<System.Security.SecurityCritical>]
abstract member Contains : System.DirectoryServices.AccountManagement.Principal -> bool
override this.Contains : System.DirectoryServices.AccountManagement.Principal -> bool
Public Function Contains (principal As Principal) As Boolean

Parameters

principal
Principal

A Principal object.

Returns

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

Implements

Attributes

Applies to

Contains(UserPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

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

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

Parameters

user
UserPrincipal

A UserPrincipal object.

Returns

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

Attributes

Applies to

Contains(PrincipalContext, IdentityType, String)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

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);
public bool Contains (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, 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
[<System.Security.SecurityCritical>]
member this.Contains : System.DirectoryServices.AccountManagement.PrincipalContext * System.DirectoryServices.AccountManagement.IdentityType * string -> bool
Public Function Contains (context As PrincipalContext, identityType As IdentityType, identityValue As String) As Boolean

Parameters

context
PrincipalContext

The PrincipalContext object of the principal.

identityType
IdentityType

An IdentityType object that specifies the format of identityValue.

identityValue
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.

Attributes

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