ProvideDesignerMetadataAttribute Class

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

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

Syntax

‘선언
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := True, Inherited := True)> _
Public NotInheritable Class ProvideDesignerMetadataAttribute _
    Inherits RegistrationAttribute
‘사용 방법
Dim instance As ProvideDesignerMetadataAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class ProvideDesignerMetadataAttribute : RegistrationAttribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple = true, Inherited = true)]
public ref class ProvideDesignerMetadataAttribute sealed : public RegistrationAttribute
[<SealedAttribute>]
[<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = true)>]
type ProvideDesignerMetadataAttribute =  
    class
        inherit RegistrationAttribute
    end
public final class ProvideDesignerMetadataAttribute extends RegistrationAttribute

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 {}

참고

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

Inheritance Hierarchy

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

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

ProvideDesignerMetadataAttribute Members

Microsoft.VisualStudio.Shell.Design Namespace