1 //------------------------------------------------------------------------------
2 // <copyright file="ProvideAutomationObjectAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace Microsoft
.VisualStudio
.Shell
{
10 using System
.Globalization
;
11 using System
.Runtime
.InteropServices
;
12 using Microsoft
.Win32
;
14 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute"]' />
16 /// This attribute declares that a package provides a particular automation object. The attributes on a
17 /// package do not control the behavior of the package, but they can be used by registration
18 /// tools to register the proper information with Visual Studio.
20 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=true, Inherited
=true)]
21 public sealed class ProvideAutomationObjectAttribute
: RegistrationAttribute
{
24 private string description
;
26 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationAttribute.ProvideAutomationObjectAttribute"]' />
28 /// Creates a new ProvideAutomationObjectAttribute.
30 public ProvideAutomationObjectAttribute(string objectName
)
32 if (objectName
== null) {
33 throw new ArgumentNullException("ObjectName");
39 /// <include file='doc\ProvideAutomationAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute.Name"]' />
41 /// Returns the name of the automation object declared in this attribute.
49 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute.Description"]' />
51 /// The description of the automation object declared in this attribute.
53 public string Description
63 private string GetAutomationRegKey(Guid packageGuid
)
65 return string.Format(CultureInfo
.InvariantCulture
, "Packages\\{0}\\Automation", packageGuid
.ToString("B"));
68 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="Register"]' />
70 /// Called to register this attribute with the given context. The context
71 /// contains the location where the registration inforomation should be placed.
72 /// it also contains information such as the type being registered, and path information.
74 /// This method is called both for registration and unregistration. The difference is
75 /// that unregistering just uses a hive that reverses the changes applied to it.
77 public override void Register(RegistrationContext context
)
79 using (Key childKey
= context
.CreateKey(GetAutomationRegKey(context
.ComponentType
.GUID
)))
81 string descValue
= (Description
== null) ? "" : Description
;
82 childKey
.SetValue(Name
, descValue
);
86 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute.Unregister"]' />
88 /// Removes the registration information from the registration context.
90 public override void Unregister(RegistrationContext context
)
92 context
.RemoveKey(GetAutomationRegKey(context
.ComponentType
.GUID
));