This documentation is archived and is not being maintained.

AddInToken Class

Represents an add-in that can be activated.

Namespace:  System.AddIn.Hosting
Assembly:  System.AddIn (in System.AddIn.dll)

'Declaration
<SerializableAttribute> _
Public NotInheritable Class AddInToken _
	Implements IEnumerable(Of QualificationDataItem), IEnumerable
'Usage
Dim instance As AddInToken

An AddInToken object represents an add-in, and its associated pipeline segments, that can be activated. The token contains the name, assembly name, description, publisher, and version of the add-in that it represents.

Use the AddInStore.FindAddIns method to get a collection of tokens that represent add-ins whose pipelines match a specified host view. Use the AddInStore.FindAddIn method to get a collection of tokens that represent all the pipelines for a specified add-in that match a specified host view.

To activate an add-in, pass the token that represents the desired add-in to the Activate method. This method returns an instance of the type that represents the host view of the add-in.

The Activate method has several overloads. When you use an overload that does not require the name of an application domain as one of its parameters, a new application domain for the add-in is automatically created.

You can use Language-Integrated Query (LINQ) extension methods to perform queries on an AddInToken, treating the token as a collection of QualificationDataItem structures.

This section contains two examples. The first example activates an add-in that has been selected by using the ChooseAddIn method, and the second example shows the ChooseAddIn method.

Example 1

The following example shows how to activate an add-in with a token.

'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)

Example 2

The following example shows the custom ChooseAddIn method, which enumerates an AddInToken collection. The user selects a token from this collection to activate the corresponding add-in.

' Method to select a token by  
' enumeratng the AddInToken collection. 

Private Shared Function ChooseAddIn(ByVal tokens As System.Collections.ObjectModel.Collection(Of AddInToken)) As AddInToken
    If (tokens.Count = 0) Then
        Console.WriteLine("No add-ins are available")
        Return Nothing 
    End If
    Console.WriteLine("Available add-ins: ")
    ' Show the token properties for each token  
    ' in the AddInToken collection (tokens), 
    ' preceded by the add-in number in [] brackets. 

    Dim tokNumber As Integer = 1
    For Each tok As AddInToken In tokens
        Console.WriteLine(vbTab & "{0}: {1} - {2}" & _
                vbLf & vbTab & "{3}" & _
                vbLf & vbTab & "{4}" & _
                vbLf & vbTab & "{5} - {6}", _
                tokNumber.ToString, tok.Name, _
                tok.AddInFullName, tok.AssemblyName, _
                tok.Description, tok.Version, tok.Publisher)
        tokNumber = tokNumber + 1
    Next
    Console.WriteLine("Which calculator do you want to use?")
    Dim line As String = Console.ReadLine
    Dim selection As Integer 
    If Int32.TryParse(line, selection) Then 
        If (selection <= tokens.Count) Then 
            Return tokens((selection - 1))
        End If 
    End If
    Console.WriteLine("Invalid selection: {0}. Please choose again.", line)
    Return ChooseAddIn(tokens)

End Function

System.Object
  System.AddIn.Hosting.AddInToken

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Show: