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)

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

[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, 
	Inherited = true)]
public sealed class ProvideDesignerMetadataAttribute : RegistrationAttribute

NameDescription
System_CAPS_pubmethodProvideDesignerMetadataAttribute(Type, Type)

Initializes a new instance of ProvideDesignerMetadataAttribute, associating a new metadata Type with the current Type.

NameDescription
System_CAPS_pubpropertyIsGlobal

Gets or sets the scope of the metadata modifications provided by an instance ProvideDesignerMetadataAttribute

System_CAPS_pubpropertyMetadataType

Gets the type of the metadata.

System_CAPS_pubpropertyRuntimeType

Gets the runtime type.

System_CAPS_pubpropertyTypeId

Gets the current instance of this attribute.(Inherited from RegistrationAttribute.)

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

System_CAPS_noteNote

 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.

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.

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

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

Return to top
Show: