FeatureConnector<TFeatureProviderType> 类

为所有基于功能连接器的扩展性提供基实现。

继承层次结构

System.Object
  Microsoft.Windows.Design.Features.FeatureConnector<TFeatureProviderType>
    Microsoft.Windows.Design.Policies.PolicyDrivenFeatureConnector<TFeatureProviderType>

命名空间:  Microsoft.Windows.Design.Features
程序集:  Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)

语法

声明
Public MustInherit Class FeatureConnector(Of TFeatureProviderType As FeatureProvider) _
    Implements IDisposable
public abstract class FeatureConnector<TFeatureProviderType> : IDisposable
where TFeatureProviderType : FeatureProvider
generic<typename TFeatureProviderType>
where TFeatureProviderType : FeatureProvider
public ref class FeatureConnector abstract : IDisposable
[<AbstractClass>]
type FeatureConnector<'TFeatureProviderType when 'TFeatureProviderType : FeatureProvider> =  
    class
        interface IDisposable
    end
JScript 不支持泛型类型或方法。

类型参数

  • TFeatureProviderType
    功能提供程序的类型。

FeatureConnector<TFeatureProviderType> 类型公开以下成员。

构造函数

  名称 说明
受保护的方法 FeatureConnector<TFeatureProviderType> 初始化 FeatureConnector<TFeatureProviderType> 类的新实例。

页首

属性

  名称 说明
受保护的属性 Context 获取功能连接器的编辑上下文。
受保护的属性 Manager 获取功能连接器的 FeatureManager

页首

方法

  名称 说明
受保护的方法 CreateFeatureProviders(Type) 基于提供的类型创建一个与功能连接器相关联的功能提供程序的新列表。
受保护的方法 CreateFeatureProviders<TSubtype>(Type) 基于提供的类型和子类型创建一个与功能连接器相关联的功能提供程序的新列表。
公共方法 Dispose() 释放由 FeatureConnector<TFeatureProviderType> 占用的所有资源。
受保护的方法 Dispose(Boolean) 释放 FeatureConnector<TFeatureProviderType> 占用的非托管资源,也可以选择释放托管资源。
公共方法 Equals 确定指定的 Object 是否等于当前的 Object。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (重写 Object.Finalize()。)
公共方法 GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)

页首

备注

需要实现与 WPF 设计器最深层的集成时,可从 FeatureConnector<TFeatureProviderType> 抽象类派生。 功能连接器可以订阅全局服务,并可以添加它们自己的服务。

功能提供程序使用 FeatureConnectorAttribute 指定相关联的功能连接器。

FeatureConnector<TFeatureProviderType> 基类为泛型并且使用 FeatureConnector<TFeatureProviderType> 所承载的功能提供程序的类型。

功能连接器是按需创建的。 当 FeatureManager 类在 FeatureProvider 上发现 FeatureConnectorAttribute 时,便会创建指定的 FeatureConnector<TFeatureProviderType>(如果它尚不存在)。

FeatureConnector<TFeatureProviderType> 抽象类实现 IDisposable 接口,后者提升简单的清理实现。

FeatureConnector<TFeatureProviderType> 类的大多数功能在受保护的 CreateFeatureProviders 方法中实现。 将一个对象传入此方法会使功能连接器在该对象上搜索 FeatureAttribute 类型。 如果找到这些特性,则创建与每个特性相关联的 FeatureProvider 实例,并以列表形式返回这些实例。

示例

下面的代码示例演示如何从 FeatureConnector<TFeatureProviderType> 类派生以将名为 DiagnosticsMenuProvider 的自定义功能提供程序与名为 IDiagnosticsService 的自定义服务连接起来。 有关完整的代码列表,请参见如何:创建自定义功能连接器

' The IDiagnosticsService specifies a simple interface for showing
' a FeatureManagerDiagnostics window.
Interface IDiagnosticsService
    Sub ShowWindow() 
End Interface


...


' The DiagnosticsFeatureConnector publishes the IDiagnosticsService. 
Class DiagnosticsFeatureConnector
    Inherits FeatureConnector(Of DiagnosticsMenuProvider)
    Implements IDiagnosticsService

    Dim fmdWindow As FeatureManagerDiagnostics

    Public Sub New(ByVal manager As FeatureManager) 
        MyBase.New(manager)

        Context.Services.Publish(Of IDiagnosticsService)(Me)

    End Sub

    ' The showWindow method creates a FeatureManagerDiagnostics
    ' window and shows it.
    Public Sub ShowWindow() Implements IDiagnosticsService.ShowWindow

        If fmdWindow IsNot Nothing Then

            ' Show the FeatureManagerDiagnostics window.
            fmdWindow.Show()

            ' Activate the 
            fmdWindow.Activate()

        Else

            fmdWindow = New FeatureManagerDiagnostics()
            fmdWindow.Initialize(Manager)
            AddHandler fmdWindow.Closed, AddressOf fmdWindow_Closed
            fmdWindow.Show()

        End If

    End Sub

    Sub fmdWindow_Closed(ByVal sender As Object, ByVal e As EventArgs)

        fmdWindow = Nothing

    End Sub

End Class
// The IDiagnosticsService specifies a simple interface for showing
// a FeatureManagerDiagnostics window.
interface IDiagnosticsService 
{
    void ShowWindow();
}


...


// The DiagnosticsFeatureConnector publishes the IDiagnosticsService. 
class DiagnosticsFeatureConnector : FeatureConnector<DiagnosticsMenuProvider>,
    IDiagnosticsService 
{
    FeatureManagerDiagnostics fmdWindow;

    public DiagnosticsFeatureConnector(FeatureManager manager)
        : base(manager) 
    {
        Context.Services.Publish<IDiagnosticsService>(this);
    }

    #region IDiagnosticsService Members

    // The showWindow method creates a FeatureManagerDiagnostics
    // window and shows it.
    public void ShowWindow() 
    {
        if (fmdWindow != null) 
        {
            fmdWindow.Show();
            fmdWindow.Activate();
        }
        else 
        {
            fmdWindow = new FeatureManagerDiagnostics();
            fmdWindow.Initialize(Manager);
            fmdWindow.Closed += new EventHandler(fmdWindow_Closed); 
            fmdWindow.Show();
        }
    }

    void fmdWindow_Closed(object sender, EventArgs e)
    {
        fmdWindow = null; 
    }

    #endregion
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参见

参考

Microsoft.Windows.Design.Features 命名空间

FeatureManager

FeatureProvider

FeatureConnectorAttribute

其他资源

如何:创建自定义功能连接器

功能提供程序和功能连接器

了解 WPF 设计器扩展性