Прочетете на английски Редактиране

Споделяне чрез


AddInToken.Activate Method

Definition

Activates an add-in.

Overloads

Activate<T>(AddInEnvironment)

Activates an add-in in the environment of another add-in.

Activate<T>(AddInSecurityLevel)

Activates an add-in with a specified trust level in a new application domain.

Activate<T>(AppDomain)

Activates an add-in in an existing application domain.

Activate<T>(PermissionSet)

Activates an add-in with a specified permission set in a new application domain.

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)

Activates an add-in in an external process, in a new application domain, and with a specified permission set.

Activate<T>(AddInSecurityLevel, String)

Activates an add-in in a new application domain with a specified name and trust level.

Activate<T>(AddInEnvironment)

Activates an add-in in the environment of another add-in.

C#
public T Activate<T>(System.AddIn.Hosting.AddInEnvironment environment);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

environment
AddInEnvironment

The application domain and process that contains the original add-in.

Returns

T

The host view of the add-in.

Examples

The following example activates one add-in in an automatically generated application domain with a specified security level. 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.

C#
// 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));

Remarks

This method overload activates the add-in in the same application domain and process as the add-in from which environment was obtained.

See also

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Activate<T>(AddInSecurityLevel)

Activates an add-in with a specified trust level in a new application domain.

C#
public T Activate<T>(System.AddIn.Hosting.AddInSecurityLevel trustLevel);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

trustLevel
AddInSecurityLevel

One of the enumeration values that specifies the trust level.

Returns

T

The host view of the add-in.

Examples

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.

C#
//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);

Remarks

This method overload loads the add-in into an automatically generated application domain. 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. 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.

See also

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Activate<T>(AppDomain)

Activates an add-in in an existing application domain.

C#
public T Activate<T>(AppDomain target);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

target
AppDomain

The application domain that the add-in should be activated in.

Returns

T

The host view of the add-in.

Exceptions

Full-trust permission is demanded. A caller in the call chain does not have sufficient permission.

Examples

The following example activates an add-in in an application domain that is being used by another add-in. The code for the first add-in is provided in the AddInToken class.

C#
// 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));

Remarks

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.

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Activate<T>(PermissionSet)

Activates an add-in with a specified permission set in a new application domain.

C#
public T Activate<T>(System.Security.PermissionSet permissions);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

permissions
PermissionSet

The permissions granted for the add-in.

Returns

T

The host view of the add-in.

Exceptions

permissions is null.

Remarks

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

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Activate<T>(AddInProcess, AddInSecurityLevel)

Activates an add-in in an external process, in a new application domain, and with a specified trust level.

C#
public T Activate<T>(System.AddIn.Hosting.AddInProcess process, System.AddIn.Hosting.AddInSecurityLevel level);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

process
AddInProcess

The external process in which to activate the add-in.

level
AddInSecurityLevel

One of the enumeration values that specifies the trust level.

Returns

T

The host view of the add-in.

Examples

The following example creates a new process and activates an add-in in that process with a full trust security level.

C#
// 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);

Remarks

This method sets the base directory for the application domain to be the location of the add-in assembly. 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.

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Activate<T>(AddInProcess, PermissionSet)

Activates an add-in in an external process, in a new application domain, and with a specified permission set.

C#
public T Activate<T>(System.AddIn.Hosting.AddInProcess process, System.Security.PermissionSet permissionSet);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

process
AddInProcess

The external process in which to activate the add-in.

permissionSet
PermissionSet

The required permission set granted for the add-in.

Returns

T

The host view of the add-in.

Remarks

This method sets the base directory for the application domain to be the location of the add-in assembly. 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.

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Activate<T>(AddInSecurityLevel, String)

Activates an add-in in a new application domain with a specified name and trust level.

C#
public T Activate<T>(System.AddIn.Hosting.AddInSecurityLevel trustLevel, string appDomainName);

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

trustLevel
AddInSecurityLevel

One of the enumeration values that specifies the trust level.

appDomainName
String

The friendly name to assign to the new application domain.

Returns

T

The host view of the add-in.

Remarks

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

Applies to

.NET Framework 4.8.1 и други версии
Продукт Версии
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1