AddInToken Class

Definition

Represents an add-in that can be activated.

public ref class AddInToken sealed : System::Collections::Generic::IEnumerable<System::AddIn::Hosting::QualificationDataItem>
[System.Serializable]
public sealed class AddInToken : System.Collections.Generic.IEnumerable<System.AddIn.Hosting.QualificationDataItem>
type AddInToken = class
    interface seq<QualificationDataItem>
    interface IEnumerable
Public NotInheritable Class AddInToken
Implements IEnumerable(Of QualificationDataItem)
Inheritance
AddInToken
Attributes
Implements

Examples

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

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 static AddInToken ChooseAddIn(Collection<AddInToken> tokens)
{
    if (tokens.Count == 0)
    {
        Console.WriteLine("No add-ins are available");
        return null;
    }

    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.
    int tokNumber = 1;
    foreach (AddInToken tok in tokens)
    {
        Console.WriteLine(String.Format("\t[{0}]: {1} - {2}\n\t{3}\n\t\t {4}\n\t\t {5} - {6}",
            tokNumber.ToString(), 
            tok.Name,
            tok.AddInFullName,
            tok.AssemblyName,
            tok.Description,
            tok.Version,
            tok.Publisher));
        tokNumber++;
    }

    Console.WriteLine("Which calculator do you want to use?");
    String line = Console.ReadLine();
    int selection;
    if (Int32.TryParse(line, out selection))
    {
        if (selection <= tokens.Count)
        {
            return tokens[selection - 1];
        }
    }
    Console.WriteLine("Invalid selection: {0}. Please choose again.", line);
    return ChooseAddIn(tokens);
}
' 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

Remarks

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.

Properties

AddInFullName

Gets the namespace and type of the add-in.

AssemblyName

Gets the name of the assembly that contains the add-in.

Description

Gets the description of the add-in.

EnableDirectConnect

Gets or sets a value that indicates whether add-ins should be directly connected to their hosts when conditions permit.

Name

Gets the name of the add-in.

Publisher

Gets the publisher of the add-in.

QualificationData

Gets a dictionary of data about the segments in the pipeline associated with the current token.

Version

Gets the version of the add-in, as specified in the AddInAttribute attribute.

Methods

Activate<T>(AddInEnvironment)

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

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)

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

Activate<T>(AddInSecurityLevel, String)

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

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.

Equals(Object)

Determines whether a specified object is equal to the current instance.

GetEnumerator()

Returns an enumerator for the qualification data of the pipeline segments that are associated with this token.

GetHashCode()

Serves as a hash function for a token.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the token.

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Returns an enumerator for the qualification data of the pipeline segments that are associated with this token.

Extension Methods

CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>)

Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>)

Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>)

Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>)

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>)

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to

See also