PrincipalCollection.Add 方法

定义

将指定的主体添加到集合的末尾。Adds the specified principal to the end of the collection.

重载

Add(ComputerPrincipal)

将指定的 ComputerPrincipal 对象添加到集合末尾。Adds the specified ComputerPrincipal object to the end of the collection.

Add(GroupPrincipal)

将指定的 GroupPrincipal 对象添加到集合末尾。Adds the specified GroupPrincipal object to the end of the collection.

Add(Principal)

将指定的 Principal 对象添加到集合末尾。Adds the specified Principal object to the end of the collection.

Add(UserPrincipal)

将指定的 UserPrincipal 对象添加到集合末尾。Adds the specified UserPrincipal object to the end of the collection.

Add(PrincipalContext, IdentityType, String)

搜索与参数匹配的 Principal 对象,并将该对象添加到集合的末尾。Searches for a Principal object that matches the parameters, and adds it to the end of the collection.

注解

与 @no__t 0 和 Contains 一样,此函数有四种重载,但它们都执行相同的操作。As with Remove and Contains, There are four overloads to this function, but they all do the same thing. 额外重载只是为了提高可用性,因此使用 IntelliSense 的开发人员可以查看采用 UserPrincipalGroupPrincipalComputerPrincipal 对象的重载。The extra overloads are only implemented to improve usability, so that developers using IntelliSense see overloads that take a UserPrincipal, GroupPrincipal, or ComputerPrincipal object. 调用任何一个用户、组或计算机重载与调用 @no__t 0 重载完全相同。Calling any one of the User, Group, or Computer overloads is exactly equivalent to calling the Principal overload.

Add(ComputerPrincipal)

将指定的 ComputerPrincipal 对象添加到集合末尾。Adds the specified ComputerPrincipal object to the end of the collection.

public:
 void Add(System::DirectoryServices::AccountManagement::ComputerPrincipal ^ computer);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
member this.Add : System.DirectoryServices.AccountManagement.ComputerPrincipal -> unit
Public Sub Add (computer As ComputerPrincipal)

参数

computer
ComputerPrincipal

一个 ComputerPrincipal 对象。A ComputerPrincipal object.

属性

注解

此函数可能会引发以下异常:This function can throw the following exceptions:

例外Exception 说明Description
PrincipalExistsException computer 已存在于集合中。computer already exists in the collection.

Add(GroupPrincipal)

将指定的 GroupPrincipal 对象添加到集合末尾。Adds the specified GroupPrincipal object to the end of the collection.

public:
 void Add(System::DirectoryServices::AccountManagement::GroupPrincipal ^ group);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.GroupPrincipal group);
member this.Add : System.DirectoryServices.AccountManagement.GroupPrincipal -> unit
Public Sub Add (group As GroupPrincipal)

参数

group
GroupPrincipal

一个 ComputerPrincipal 对象。A ComputerPrincipal object.

属性

注解

此函数可能会引发以下异常:This function can throw the following exceptions:

例外Exception 说明Description
PrincipalExistsException group 已存在于集合中。group already exists in the collection.

Add(Principal)

将指定的 Principal 对象添加到集合末尾。Adds the specified Principal object to the end of the collection.

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

参数

principal
Principal

一个 Principal 对象。A Principal object.

实现

属性

注解

此函数可能会引发以下异常:This function can throw the following exceptions:

例外Exception 说明Description
PrincipalExistsException principal 已存在于集合中。principal already exists in the collection.

Add(UserPrincipal)

将指定的 UserPrincipal 对象添加到集合末尾。Adds the specified UserPrincipal object to the end of the collection.

public:
 void Add(System::DirectoryServices::AccountManagement::UserPrincipal ^ user);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.UserPrincipal user);
member this.Add : System.DirectoryServices.AccountManagement.UserPrincipal -> unit
Public Sub Add (user As UserPrincipal)

参数

user
UserPrincipal

一个 UserPrincipal 对象A UserPrincipal object

属性

注解

此函数可能会引发以下异常:This function can throw the following exceptions:

例外Exception 说明Description
PrincipalExistsException user 已存在于集合中。user already exists in the collection.

Add(PrincipalContext, IdentityType, String)

搜索与参数匹配的 Principal 对象,并将该对象添加到集合的末尾。Searches for a Principal object that matches the parameters, and adds it to the end of the collection.

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

参数

context
PrincipalContext

要添加到集合的主体的 PrincipalContext 对象。The PrincipalContext object for the principal to be added to the collection.

identityType
IdentityType

一个 IdentityType 对象,该对象指定 identityValue 的格式An IdentityType object that specifies the format of identityValue

identityValue
String

一个标识主体的字符串,采用 identityType 所指定的格式A string that identifies the principal, in the format specified by identityType

属性

注解

此函数可能会引发以下异常:This function can throw the following exceptions:

例外Exception 说明Description
PrincipalExistsException 集合中已存在与这些参数相匹配的主体。The principal matching these parameters already exists in the collection.
NoMatchingPrincipalException 找不到与指定参数匹配的主体。No principal matching the specified parameters was found.
MultipleMatchesException 多个主体与指定参数匹配。More than one principal matches the specified parameters.
ArgumentException identityType 是空字符串identityType is an empty string

适用于