共用方式為


HOW TO:使用限定性條件資料

您可以藉由套用一個或多個 QualificationDataAttribute 屬性至管線區段的方式,針對任何目的指派限定性條件資料給該區段。 每個屬性都會指定簡單名稱/值組的字串資料。 例如,您可以藉由指定名稱/值組 "Security" 和 "FullTrust",指出增益集應以完全信任啟動。 同樣地,您可以藉由指定名稱/值組 "Isolation" 和 "NewProcess",指出管線區段應隔離於自己的處理序中。

若要將限定性條件資料套用至管線區段

  • 請使用 QualificationDataAttribute 屬性。

    ' This pipeline segment has
    ' two attributes:
    ' 1 - An AddInAttribute to identify
    '     this segment as an add-in.
    '
    ' 2 - A QualificationDataAttribute to
    '     indicate that the add-in should
    '     be loaded into a new application domain.
    
    <AddIn("Calculator Add-in", Version:="2.0.0.0")> _
    <QualificationData("Isolation", "NewAppDomain")> _
        Public Class SampleV2AddIn
    
    // This pipeline segment has
    // two attributes:
    // 1 - An AddInAttribute to identify
    //     this segment as an add-in.
    //
    // 2 - A QualificationDataAttribute to
    //     indicate that the add-in should
    //     be loaded into a new application domain.
    
        [AddIn("Calculator Add-in",Version="2.0.0.0")]
        [QualificationData("Isolation", "NewAppDomain")]
        public class SampleV2AddIn : Calculator2
        {
    

若要判斷特定管線區段的限定性條件資料

  • 使用 AddInToken 物件的 QualificationData 屬性區段字典,以及與語彙基元相關的限定性條件資料,然後使用適當的 AddInSegmentType 值取得字典,其中包含組成所需區段之限定性條件資料的名稱/值組。

    ' Use qualification data to control
    ' how an add-in should be activated.
    
    If selectedToken.QualificationData(AddInSegmentType.AddIn)("Isolation").Equals("NewProcess") Then
        ' Create an external process.
        Dim external As AddInProcess = New AddInProcess
    
        ' Activate an add-in in an automatically generated
        ' application domain with a full trust security level.
        Dim CalcAddin5 As Calculator = _
            selectedToken.Activate(Of Calculator)(external, _
                AddInSecurityLevel.FullTrust)
        Console.WriteLine("Add-in activated per qualification data.")
    Else
        Console.WriteLine("This add-in is not designated to be activated in a new process.")
    End If
    
    // Use qualification data to control 
    // how an add-in should be activated.
    
    if (selectedToken.QualificationData[AddInSegmentType.AddIn]["Isolation"].Equals("NewProcess"))
    {
        // Create an external process.
        AddInProcess external = new AddInProcess();
    
        // Activate an add-in in the new process
        // with the full trust security level.
        Calculator CalcAddIn5 =
            selectedToken.Activate<Calculator>(external,
            AddInSecurityLevel.FullTrust);
        Console.WriteLine("Add-in activated per qualification data.");
    }
    else
        Console.WriteLine("This add-in is not designated to be activated in a new process.");
    

    如果沒有區段的限定性條件資料,其名稱/值組字典就會是空的。

    注意事項注意事項

    增益集模型不會使用套用至增益集主應用程式檢視的限定性條件資料。因此,AddInSegmentType.HostViewOfAddIn 的字典一定是空白。

若要列出所有管線區段的限定性條件資料

  • 列舉 AddInToken 物件,就如同 QualificationDataItem 結構的集合。

    ' Show the qualification data for each
    ' token in an AddInToken collection.
    For Each token As AddInToken In tokens
        For Each qdi As QualificationDataItem In token
            Console.WriteLine("{0} {1}\n\t QD Name: {2}, QD Value: {3}", _
                token.Name, qdi.Segment, qdi.Name, qdi.Value)
        Next
    Next
    
    // Show the qualification data for each
    // token in an AddInToken collection.
    foreach (AddInToken token in tokens)
    {
        foreach (QualificationDataItem qdi in token)
        {
            Console.WriteLine("{0} {1}\n\t QD Name: {2}, QD Value: {3}",
                token.Name,
                qdi.Segment, 
                qdi.Name, 
                qdi.Value);
        }
    }
    
    
    注意事項注意事項

    增益集模型不會使用套用至增益集主應用程式檢視的限定性條件資料。因此,當您列舉限定性條件資料時,不會找到 Segment 屬性為 AddInSegmentType.HostViewOfAddIn 的任何項目。

請參閱

概念

增益集和擴充性