AddInToken.Activate AddInToken.Activate AddInToken.Activate AddInToken.Activate Method

定义

激活外接程序。Activates an add-in.

重载

Activate<T>(AddInEnvironment) Activate<T>(AddInEnvironment) Activate<T>(AddInEnvironment) Activate<T>(AddInEnvironment)

在另一个外接程序的环境中激活一个外接程序。Activates an add-in in the environment of another add-in.

Activate<T>(AddInSecurityLevel) Activate<T>(AddInSecurityLevel) Activate<T>(AddInSecurityLevel) Activate<T>(AddInSecurityLevel)

在新应用程序域中激活具有指定信任级别的外接程序。Activates an add-in with a specified trust level in a new application domain.

Activate<T>(AppDomain) Activate<T>(AppDomain) Activate<T>(AppDomain) Activate<T>(AppDomain)

在现有应用程序域中激活外接程序。Activates an add-in in an existing application domain.

Activate<T>(PermissionSet) Activate<T>(PermissionSet) Activate<T>(PermissionSet) Activate<T>(PermissionSet)

在新应用程序域中激活具有指定权限集的外接程序。Activates an add-in with a specified permission set in a new application domain.

Activate<T>(AddInProcess, AddInSecurityLevel) Activate<T>(AddInProcess, AddInSecurityLevel) Activate<T>(AddInProcess, AddInSecurityLevel) Activate<T>(AddInProcess, AddInSecurityLevel)

在外部进程中(且在新应用程序域内)激活具有指定信任级别的外接程序。Activates an add-in in an external process, in a new application domain, and with a specified trust level.

Activate<T>(AddInProcess, PermissionSet) Activate<T>(AddInProcess, PermissionSet) Activate<T>(AddInProcess, PermissionSet)

在外部进程中(且在新应用程序域内)激活具有指定权限集的外接程序。Activates an add-in in an external process, in a new application domain, and with a specified permission set.

Activate<T>(AddInSecurityLevel, String) Activate<T>(AddInSecurityLevel, String) Activate<T>(AddInSecurityLevel, String) Activate<T>(AddInSecurityLevel, String)

在具有指定名称和信任级别的新应用程序域中激活外接程序。Activates an add-in in a new application domain with a specified name and trust level.

Activate<T>(AddInEnvironment) Activate<T>(AddInEnvironment) Activate<T>(AddInEnvironment) Activate<T>(AddInEnvironment)

在另一个外接程序的环境中激活一个外接程序。Activates an add-in in the environment of another add-in.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInEnvironment ^ environment);
public T Activate<T> (System.AddIn.Hosting.AddInEnvironment environment);
member this.Activate : System.AddIn.Hosting.AddInEnvironment -> 'T
Public Function Activate(Of T) (environment As AddInEnvironment) As T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

environment
AddInEnvironment AddInEnvironment AddInEnvironment AddInEnvironment

包含原始外接程序的应用程序域和进程。The application domain and process that contains the original add-in.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

示例

下面的示例在具有指定安全级别的自动生成的应用程序域中激活一个外接程序。The following example activates one add-in in an automatically generated application domain with a specified security level. 然后, 它将在同一应用程序域中激活第二个外接程序, 并使用第一个外接程序的AddInEnvironment对象处理第一个外接程序。It then activates a second add-in in the same application domain and process as the first by using the first add-in's AddInEnvironment object.

// Get the AddInController of a 
// currently actived add-in (CalcAddIn).
AddInController aiController = AddInController.GetAddInController(CalcAddIn);

// Select another token.
AddInToken selectedToken2 = ChooseAddIn(tokens);

// Activate a second add-in, CalcAddIn2, in the same
// appliation domain and process as the first add-in by passing
// the first add-in's AddInEnvironment object to the Activate method.
AddInEnvironment aiEnvironment = aiController.AddInEnvironment;
Calculator CalcAddIn2 =
	selectedToken2.Activate<Calculator>(aiEnvironment);

// Get the AddInController for the second add-in to compare environments.
AddInController aiController2 = AddInController.GetAddInController(CalcAddIn2);
Console.WriteLine("Add-ins in same application domain: {0}", aiController.AppDomain.Equals(aiController2.AppDomain));
Console.WriteLine("Add-ins in same process: {0}", aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process));
' Get the AddInController of a 
' currently activated add-in (CalcAddIn).
Dim aiController As AddInController = AddInController.GetAddInController(CalcAddIn)

' Select another token.
Dim selectedToken2 As AddInToken = ChooseAddIn(tokens)

' Activate a second add-in, CalcAddIn2, in the same
' appliation domain and process as the first add-in by passing
' the first add-in's AddInEnvironment object to the Activate method.

Dim aiEnvironment As AddInEnvironment = aiController.AddInEnvironment
Dim CalcAddIn2 As Calculator = _
    selectedToken2.Activate(Of Calculator)(aiEnvironment)

' Get the AddInController for the second add-in to compare environments.
Dim aiController2 As AddInController = AddInController.GetAddInController(CalcAddIn2)

Console.WriteLine("Add-ins in same application domain: {0}", _
    aiController.AppDomain.Equals(aiController2.AppDomain))
Console.WriteLine("Add-ins in same process: {0}", _
    aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process))

注解

此方法重载会激活同一个应用程序域中的外接程序, 并将作为从中environment获取的外接程序进行处理。This method overload activates the add-in in the same application domain and process as the add-in from which environment was obtained.

另请参阅

Activate<T>(AddInSecurityLevel) Activate<T>(AddInSecurityLevel) Activate<T>(AddInSecurityLevel) Activate<T>(AddInSecurityLevel)

在新应用程序域中激活具有指定信任级别的外接程序。Activates an add-in with a specified trust level in a new application domain.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInSecurityLevel trustLevel);
public T Activate<T> (System.AddIn.Hosting.AddInSecurityLevel trustLevel);
member this.Activate : System.AddIn.Hosting.AddInSecurityLevel -> 'T
Public Function Activate(Of T) (trustLevel As AddInSecurityLevel) As T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

trustLevel
AddInSecurityLevel AddInSecurityLevel AddInSecurityLevel AddInSecurityLevel

用于指定信任级别的枚举值之一。One of the enumeration values that specifies the trust level.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

示例

下面的示例演示如何在具有指定安全级别的自动生成的应用程序域中激活由所选标记标识的外接程序。The following example shows how to activate an add-in, identified by the chosen token, in an automatically generated application domain with a specified security level.

//Ask the user which add-in they would like to use.
AddInToken selectedToken = ChooseAddIn(tokens);

//Activate the selected AddInToken in a new
//application domain with the Internet trust level.
Calculator CalcAddIn = selectedToken.Activate<Calculator>(AddInSecurityLevel.Internet);
            
//Run the add-in using a custom method.
RunCalculator(CalcAddIn);
'Ask the user which add-in they would like to use.
Dim selectedToken As AddInToken = ChooseAddIn(tokens)
'Activate the selected AddInToken in a new
'application domain with the Internet trust level.
Dim CalcAddIn As Calculator = selectedToken.Activate(Of Calculator)(AddInSecurityLevel.Internet)
'Run the add-in using a custom method.
RunCalculator(CalcAddIn)

注解

此方法重载将外接程序加载到自动生成的应用程序域中。This method overload loads the add-in into an automatically generated application domain. 如果要指定新应用程序域的名称, 请使用Activate<T>(AddInSecurityLevel, String)重载。If you want to specify a name for the new application domain, use the Activate<T>(AddInSecurityLevel, String) overload.

此方法将应用程序域的基目录设置为外接程序程序集的位置。This method sets the base directory for the application domain to be the location of the add-in assembly. 它还查找配置文件 [addinassemblyname] .dll, 如果找到, 则将其设置为新应用程序域的配置文件。It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

另请参阅

Activate<T>(AppDomain) Activate<T>(AppDomain) Activate<T>(AppDomain) Activate<T>(AppDomain)

在现有应用程序域中激活外接程序。Activates an add-in in an existing application domain.

public:
generic <typename T>
 T Activate(AppDomain ^ target);
public T Activate<T> (AppDomain target);
member this.Activate : AppDomain -> 'T
Public Function Activate(Of T) (target As AppDomain) As T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

target
AppDomain AppDomain AppDomain AppDomain

应在其中激活外接程序的应用程序域。The application domain that the add-in should be activated in.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

异常

需要完全信任权限。Full-trust permission is demanded. 调用链中的调用方没有足够权限。A caller in the call chain does not have sufficient permission.

示例

下面的示例在其他外接程序所使用的应用程序域中激活外接程序。The following example activates an add-in in an application domain that is being used by another add-in. 第一个外接程序的代码在AddInToken类中提供。The code for the first add-in is provided in the AddInToken class.

// Get the application domain
// of an existing add-in (CalcAddIn).
AddInController aiCtrl = AddInController.GetAddInController(CalcAddIn);
AppDomain AddInAppDom = aiCtrl.AppDomain;

// Activate another add-in in the same application domain.
Calculator CalcAddIn3 =
	selectedToken2.Activate<Calculator>(AddInAppDom);

// Show that CalcAddIn3 was loaded
// into CalcAddIn's application domain.
AddInController aic = AddInController.GetAddInController(CalcAddIn3);
Console.WriteLine("Add-in loaded into existing application domain: {0}",
	aic.AppDomain.Equals(AddInAppDom));
' Get the application domain
' of an existing add-in (CalcAddIn).

Dim aiCtrl As AddInController = AddInController.GetAddInController(CalcAddIn)
Dim AddInAppDom As AppDomain = aiCtrl.AppDomain

' Activate another add-in in the same appliation domain.
Dim CalcAddIn3 As Calculator = selectedToken2.Activate(Of Calculator)(AddInAppDom)

' Show that the CalcAddIn3 was loaded
' into CalcCaddIn's application domain.
Dim aic As AddInController = AddInController.GetAddInController(CalcAddIn3)
Console.WriteLine("Add-in loaded into existing application domain: {0}", _
 aic.AppDomain.Equals(AddInAppDom))

注解

若要在自动生成的应用程序域中激活外接程序, Activate<T>(AddInSecurityLevel)请使用重载生成具有指定安全级别Activate<T>(AddInSecurityLevel, String)或重载的新应用程序域, 以包含应用程序域的友好名称。To activate an add-in in an automatically generated application domain, use the Activate<T>(AddInSecurityLevel) overload to generate a new application domain with a specified security level or the Activate<T>(AddInSecurityLevel, String) overload to include a friendly name for the application domain.

Activate<T>(PermissionSet) Activate<T>(PermissionSet) Activate<T>(PermissionSet) Activate<T>(PermissionSet)

在新应用程序域中激活具有指定权限集的外接程序。Activates an add-in with a specified permission set in a new application domain.

public:
generic <typename T>
 T Activate(System::Security::PermissionSet ^ permissions);
public T Activate<T> (System.Security.PermissionSet permissions);
member this.Activate : System.Security.PermissionSet -> 'T
Public Function Activate(Of T) (permissions As PermissionSet) As T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

permissions
PermissionSet PermissionSet PermissionSet PermissionSet

授予外接程序的权限。The permissions granted for the add-in.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

异常

注解

此方法重载将外接程序加载到自动生成的应用程序域中。This method overload loads the add-in into an automatically generated application domain. 它将应用程序域的基目录设置为外接程序程序集的位置。It sets the base directory for the application domain to be the location of the add-in assembly. 它还查找配置文件[addinassemblyname].dll.config , 如果找到, 则将其设置为新应用程序域的配置文件。It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

Activate<T>(AddInProcess, AddInSecurityLevel) Activate<T>(AddInProcess, AddInSecurityLevel) Activate<T>(AddInProcess, AddInSecurityLevel) Activate<T>(AddInProcess, AddInSecurityLevel)

在外部进程中(且在新应用程序域内)激活具有指定信任级别的外接程序。Activates an add-in in an external process, in a new application domain, and with a specified trust level.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInProcess ^ process, System::AddIn::Hosting::AddInSecurityLevel level);
public T Activate<T> (System.AddIn.Hosting.AddInProcess process, System.AddIn.Hosting.AddInSecurityLevel level);
member this.Activate : System.AddIn.Hosting.AddInProcess * System.AddIn.Hosting.AddInSecurityLevel -> 'T
Public Function Activate(Of T) (process As AddInProcess, level As AddInSecurityLevel) As T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

process
AddInProcess AddInProcess AddInProcess AddInProcess

在其中激活外接程序的外部进程。The external process in which to activate the add-in.

level
AddInSecurityLevel AddInSecurityLevel AddInSecurityLevel AddInSecurityLevel

用于指定信任级别的枚举值之一。One of the enumeration values that specifies the trust level.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

示例

下面的示例创建一个新进程, 并使用完全信任安全级别在该进程中激活外接程序。The following example creates a new process and activates an add-in in that process with a full trust security level.

// Create an external process.
AddInProcess pExternal = new AddInProcess();

// Activate an add-in in the external process
// with a full trust security level.
Calculator CalcAddIn4 =
	selectedToken.Activate<Calculator>(pExternal,
	AddInSecurityLevel.FullTrust);

// Show that the add-in is an external process
// by verifying that it is not in the current (host's) process.
AddInController AddinCtl = AddInController.GetAddInController(CalcAddIn4);
Console.WriteLine("Add-in in host's process: {0}",
	AddinCtl.AddInEnvironment.Process.IsCurrentProcess);
' Create an external process.
Dim pExternal As New AddInProcess()

' Activate an add-in in the external process
' with a full trust security level.
Dim CalcAddIn4 As Calculator = _
    selectedToken.Activate(Of Calculator)(pExternal, _
        AddInSecurityLevel.FullTrust)

' Show that the add-in is an external process
' by verifying that it is not in the current (host's) process.
Dim AddinCtl As AddInController = AddInController.GetAddInController(CalcAddIn4)
Console.WriteLine("Add-in in host's process: {0}", _
 AddinCtl.AddInEnvironment.Process.IsCurrentProcess)

注解

此方法将应用程序域的基目录设置为外接程序程序集的位置。This method sets the base directory for the application domain to be the location of the add-in assembly. 它还查找配置文件[addinassemblyname].dll.config , 如果找到, 则将其设置为新应用程序域的配置文件。It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

安全性

Demand
对直接调用方的完全信任。full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code.

Activate<T>(AddInProcess, PermissionSet) Activate<T>(AddInProcess, PermissionSet) Activate<T>(AddInProcess, PermissionSet)

在外部进程中(且在新应用程序域内)激活具有指定权限集的外接程序。Activates an add-in in an external process, in a new application domain, and with a specified permission set.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInProcess ^ process, System::Security::PermissionSet ^ permissionSet);
public T Activate<T> (System.AddIn.Hosting.AddInProcess process, System.Security.PermissionSet permissionSet);
member this.Activate : System.AddIn.Hosting.AddInProcess * System.Security.PermissionSet -> 'T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

process
AddInProcess AddInProcess AddInProcess AddInProcess

在其中激活外接程序的外部进程。The external process in which to activate the add-in.

permissionSet
PermissionSet PermissionSet PermissionSet PermissionSet

授予外接程序的必需权限集。The required permission set granted for the add-in.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

注解

此方法将应用程序域的基目录设置为外接程序程序集的位置。This method sets the base directory for the application domain to be the location of the add-in assembly. 它还查找配置文件[addinassemblyname].dll.config , 如果找到, 则将其设置为新应用程序域的配置文件。It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

安全性

Demand
对直接调用方的完全信任。full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code.

Activate<T>(AddInSecurityLevel, String) Activate<T>(AddInSecurityLevel, String) Activate<T>(AddInSecurityLevel, String) Activate<T>(AddInSecurityLevel, String)

在具有指定名称和信任级别的新应用程序域中激活外接程序。Activates an add-in in a new application domain with a specified name and trust level.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInSecurityLevel trustLevel, System::String ^ appDomainName);
public T Activate<T> (System.AddIn.Hosting.AddInSecurityLevel trustLevel, string appDomainName);
member this.Activate : System.AddIn.Hosting.AddInSecurityLevel * string -> 'T
Public Function Activate(Of T) (trustLevel As AddInSecurityLevel, appDomainName As String) As T

类型参数

T

表示外接程序的宿主视图的接口或抽象基类型。The interface or abstract base type that represents the host view of the add-in.

参数

trustLevel
AddInSecurityLevel AddInSecurityLevel AddInSecurityLevel AddInSecurityLevel

用于指定信任级别的枚举值之一。One of the enumeration values that specifies the trust level.

appDomainName
String String String String

要分配给新应用程序域的友好名称。The friendly name to assign to the new application domain.

返回

T T T T

外接程序的宿主视图。The host view of the add-in.

注解

如果无需指定应用程序域名, 请使用Activate<T>(AddInSecurityLevel)重载。If you do not need to specify an application domain name, use the Activate<T>(AddInSecurityLevel) overload.

此方法将应用程序域的基目录设置为外接程序程序集的位置。This method sets the base directory for the application domain to be the location of the add-in assembly. 它还查找配置文件[addinassemblyname].dll.config , 如果找到, 则将其设置为新应用程序域的配置文件。It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

适用于