Freigeben über


ProvideDesignerMetadataAttribute Class

Declares additional metadata for types or objects, allowing third parties to modify the set of metadata available on a class.

Inheritance Hierarchy

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

Namespace:  Microsoft.VisualStudio.Shell.Design
Assembly:  Microsoft.VisualStudio.Shell.Design (in Microsoft.VisualStudio.Shell.Design.dll)

Syntax

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

The ProvideDesignerMetadataAttribute type exposes the following members.

Constructors

  Name Description
Public method ProvideDesignerMetadataAttribute Initializes a new instance of ProvideDesignerMetadataAttribute, associating a new metadata Type with the current Type.

Top

Properties

  Name Description
Public property IsGlobal Gets or sets the scope of the metadata modifications provided by an instance ProvideDesignerMetadataAttribute
Public property MetadataType Gets the type of the metadata.
Public property RuntimeType Gets the runtime type.
Public property TypeId Gets the current instance of this attribute. (Inherited from RegistrationAttribute.)

Top

Methods

  Name Description
Public method Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttribute When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method Register Registers the designer metadata. (Overrides RegistrationAttribute.Register(RegistrationAttribute.RegistrationContext).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Unregister Removes the designer metadata registry key. (Overrides RegistrationAttribute.Unregister(RegistrationAttribute.RegistrationContext).)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method _Attribute.GetIDsOfNames Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfo Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfoCount Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.Invoke Provides access to properties and methods exposed by an object. (Inherited from Attribute.)

Top

Remarks

Modifications provided by an instance of ProvideDesignerMetadataAttribute applied to a VSPackage's implementation of Package can have one of two scopes:

  • Global -- for all new instances of a given component

  • Local -- pertaining only to instance of the component created on a design surface provided by the current VSPackage.

The value of IsGlobal on the attribute applied to a VSPackage's implementation of Package determines this scope.

Applying the attribute to an implementation of Package with the IsGlobal property of the ProvideDesignerMetadataAttribute object set to true, as below, changes the browser for the entire Visual Studio environment:

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

       internal class MyPackage : Package {}

If the global flag was set to false, then the metadata change is local to the current designer supported by the current VSPackage:

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

       internal class MyPackage : Package {}

Note

 At the present time, the design surface supports creating only components, and therefore only components can have local metadata. In the example above, we were attempting to modify a property, such as the Color property of an object. If IsGlobal is set to false , CustomBrowser would never appear because the designer never actually creates an instance of Color. Setting IsGlobal to false is useful for components, such as controls, timers, and dialog boxes.

Attribute Context

Applies to

Classes providing VSPackages by implementing the IVsPackage interface or the Package class.

Repeatable

Yes

Required attributes

None

Invalid attributes

None

Notes to Callers

Apply an instance of this attribute to the class implementing Package for a VSPackage if that VSPackage needs to modify a current type by changing its metadata available through the TypeDescriptor object.

Examples

To replace the color picker (the UITypeEditor implementation creating a value editor which will be provided to users when modifying color properties of an object at design time) associated with the Color class, reguires that:

  1. An instance of ProvideDesignerMetadataAttribute by applied to a VSPackage's implementation of Package to register that the VSPackage is adding a new metadata object (CustomColorAttributes) to the Color class.

  2. Provide a definition of the new metadata object (CustomColorAttributes), using the EditorAttribute to associate it with a new color picker.

  3. Create an implementation of UITypeEditor to provide a design interface to its manipulation (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
    */
}

The .NET Framework reflection mechanism will then be updated, and when users need to modify the color properties of an object, the .NET Framework environment will call GetEditor (as shown below) and obtain an instance of CustomColorEditor, not the default color editor for the Color class.

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

Thread Safety

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

See Also

Reference

Microsoft.VisualStudio.Shell.Design Namespace