1 //------------------------------------------------------------------------------
2 // <copyright file="ProvideMenuResourceAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace Microsoft
.VisualStudio
.Shell
{
10 using System
.Globalization
;
12 /// <include file='doc\ProvideMenuResourceAttribute.uex' path='docs/doc[@for="ProvideMenuResourceAttribute"]' />
14 /// This attribute declares that a package offers menu resources. When Visual Studio encounters
15 /// such a package it will merge the menu resource information in its menus. The attributes on a
16 /// package do not control the behavior of the package, but they can be used by registration
17 /// tools to register the proper information with Visual Studio.
19 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=true, Inherited
=true)]
20 public sealed class ProvideMenuResourceAttribute
: RegistrationAttribute
{
22 private short _resourceID
;
25 /// <include file='doc\ProvideMenuResourceAttribute.uex' path='docs/doc[@for="ProvideMenuResourceAttribute.ProvideMenuResourceAttribute"]' />
27 /// Creates a new ProvideMenuResourceAttribute.
29 public ProvideMenuResourceAttribute (short resourceID
, int version
) {
30 _resourceID
= resourceID
;
34 /// <include file='doc\ProvideMenuResourceAttribute.uex' path='docs/doc[@for="ProvideMenuResourceAttribute.ResourceID"]' />
36 /// Returns the native resource ID for the menu resource.
38 public short ResourceID
{
44 /// <include file='doc\ProvideMenuResourceAttribute.uex' path='docs/doc[@for="ProvideMenuResourceAttribute.Version"]' />
46 /// Returns the version of this menu resource.
54 /// <include file='doc\ProvideMenuResourceAttribute.uex' path='docs/doc[@for="Register"]' />
56 /// Called to register this attribute with the given context. The context
57 /// contains the location where the registration inforomation should be placed.
58 /// it also contains such as the type being registered, and path information.
60 /// This method is called both for registration and unregistration. The difference is
61 /// that unregistering just uses a hive that reverses the changes applied to it.
63 public override void Register(RegistrationContext context
) {
64 context
.Log
.WriteLine(SR
.GetString(SR
.Reg_NotifyMenuResource
, ResourceID
, Version
));
66 using (Key childKey
= context
.CreateKey("Menus"))
68 childKey
.SetValue(context
.ComponentType
.GUID
.ToString("B"), string.Format(CultureInfo
.InvariantCulture
, ", {0}, {1}", ResourceID
, Version
));
73 /// Called to unregister this attribute with the given context.
75 /// <param name="context">
76 /// Contains the location where the registration inforomation should be placed.
77 /// It also contains other informations as the type being registered and path information.
79 public override void Unregister(RegistrationContext context
) {
80 context
.RemoveValue("Menus", context
.ComponentType
.GUID
.ToString("B"));