ProvideDesignerMetadataAttribute 类

声明类型或对象的附加元数据,允许第三方修改将元数据中可用的类。

继承层次结构

System.Object
  System.Attribute
    Microsoft.VisualStudio.Shell.RegistrationAttribute
      Microsoft.VisualStudio.Shell.Design.ProvideDesignerMetadataAttribute

命名空间:  Microsoft.VisualStudio.Shell.Design
程序集:  Microsoft.VisualStudio.Shell.Design(在 Microsoft.VisualStudio.Shell.Design.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := True, Inherited := True)> _
Public NotInheritable Class ProvideDesignerMetadataAttribute _
    Inherits RegistrationAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class ProvideDesignerMetadataAttribute : RegistrationAttribute

ProvideDesignerMetadataAttribute 类型公开以下成员。

构造函数

  名称 说明
公共方法 ProvideDesignerMetadataAttribute 初始化 ProvideDesignerMetadataAttribute新实例,将新的元数据 Type 与当前 Type

页首

属性

  名称 说明
公共属性 IsGlobal 获取或设置实例提供元数据修改的大小 ProvideDesignerMetadataAttribute
公共属性 MetadataType 获取元数据的类型。
公共属性 RuntimeType 获取该运行时类型。
公共属性 TypeId 获取此属性的当前实例。 (继承自 RegistrationAttribute。)

页首

方法

  名称 说明
公共方法 Equals 基础结构。返回一个值,该值指示此实例是否与指定的对象相等。 (继承自 Attribute。)
公共方法 GetHashCode 返回此实例的哈希代码。 (继承自 Attribute。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
公共方法 IsDefaultAttribute 当在派生类中重写时,指示此实例的值是否是派生类的默认值。 (继承自 Attribute。)
公共方法 Match 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。 (继承自 Attribute。)
公共方法 Register 注册设计器元数据。 (重写 RegistrationAttribute.Register(RegistrationAttribute.RegistrationContext)。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)
公共方法 Unregister 移除设计器元数据注册表项。 (重写 RegistrationAttribute.Unregister(RegistrationAttribute.RegistrationContext)。)

页首

显式接口实现

  名称 说明
显式接口实现私有方法 _Attribute.GetIDsOfNames 将一组名称映射为对应的一组调度标识符。 (继承自 Attribute。)
显式接口实现私有方法 _Attribute.GetTypeInfo 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。 (继承自 Attribute。)
显式接口实现私有方法 _Attribute.GetTypeInfoCount 检索对象提供的类型信息接口的数量(0 或 1)。 (继承自 Attribute。)
显式接口实现私有方法 _Attribute.Invoke 提供对某一对象公开的属性和方法的访问。 (继承自 Attribute。)

页首

备注

ProvideDesignerMetadataAttribute 实例提供的修改应用于 Package 的 VSPackage 中实现可以具有两个范围之一:

  • 全局--为特定元素的所有新实例

  • 本地--仅与在模型中创建的组件的实例图面提供由当前 VSPackage。

IsGlobal 的值在属性的适用于 Package 的 VSPackage 中实现确定此范围。

将特性应用于 Package 的实现与下面设置为 true, ProvideDesignerMetadataAttribute 对象的 IsGlobal 属性,更改整个 Visual Studio 环境的浏览器:

       [ProvideDesignerMetadata(typeof(Color), typeof(CustomBrowser), IsGlobal=true)]

       internal class MyPackage : Package {}

如果全局标志设置为 false,则元数据来更改仅限于向当前 VSPackage 支持的枚举当前设计器:

       [ProvideDesignerMetadata(typeof(Color), typeof(CustomBrowser), IsGlobal=false)]

       internal class MyPackage : Package {}

备注

当前,该设计图面支持创建仅元素,只有元素可以具有本地元数据。在上面的示例中,我们将尝试修改一个属性,例如对象的 Color 属性。如果 IsGlobal 设置为 false , CustomBrowser 不会出现,因为设计器不实际创建 Color实例。设置为 false 的 IsGlobal 为元素非常有用,例如控件、计时器和对话框。

属性上下文

适用对象

提供 Vspackage 的类通过实现 IVsPackage 接口或 Package 类。

可重复

必需的特性

无效的特性

对调用者的说明

请应用此特性的实例于实现 VSPackage 的类 Package ,如果该 VSPackage 需要通过更改其元数据修改一个当前类型可通过 TypeDescriptor 对象。

示例

若要替换颜色选取器 (创建要提供给用户的值编辑器,当对象中修改颜色属性在设计时的) 与 Color 类, reguires 的 UITypeEditor 实现的:

  1. ProvideDesignerMetadataAttribute 实例由应用于 Package 的 VSPackage 中实现注册的 VSPackage 添加新的元数据对象 (可 Color 类的CustomColorAttributes) 。

  2. 提供新的元数据对象 (CustomColorAttributes) 的定义,使用 EditorAttribute 将其与新的颜色选取器。

  3. 创建 UITypeEditor 的实现提供设计界面对其处理 (CustomColorEditor)。

//Register the VSPackage as providing modification of the metad
[ProvideDesignerMetadata(typeof(Color), typeof(CustomColorAttributes), IGlobal=true)]
internal class CustomColorPackage : Package {
    /* 
    *package implementation details
    */
}
// Specify the editor to change this property
[EditorAttribute(typeof(CustomColorEditor), typeof(UITypeEditor))]
internal class CustomColorAttributes 
{
    /*
     * Implementation of new color settings to be used with the custom color picker
    */
}
// And, the new color editor itself

internal class CustomColorEditor : UITypeEditor {
    /*
     * Implementation of the picker
    */
}

.NET Framework 反射机制然后将是 Color 类而不是更新,并在用户需要修改对象的颜色属性, .NET Framework 环境将调用 GetEditor (如下所示) 并获取 CustomColorEditor 实例,默认颜色编辑器。

     UITypeEditor e = TypeDescriptor.GetEditor(typeof(Color), typeof(UITypeEditor));

线程安全

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

请参见

参考

Microsoft.VisualStudio.Shell.Design 命名空间