added some development tools
[windows-sources.git] / developer / VSSDK / VisualStudioIntegration / Common / Source / CSharp / Shell / ProvideAutomationAttribute.cs
blob7940fdce76dbc269810f04d09239e37c6ffca239
1 //------------------------------------------------------------------------------
2 // <copyright file="ProvideAutomationObjectAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
7 namespace Microsoft.VisualStudio.Shell {
9 using System;
10 using System.Globalization;
11 using System.Runtime.InteropServices;
12 using Microsoft.Win32;
14 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute"]' />
15 /// <devdoc>
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.
19 /// </devdoc>
20 [AttributeUsage(AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
21 public sealed class ProvideAutomationObjectAttribute : RegistrationAttribute {
23 private string name;
24 private string description;
26 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationAttribute.ProvideAutomationObjectAttribute"]' />
27 /// <devdoc>
28 /// Creates a new ProvideAutomationObjectAttribute.
29 /// </devdoc>
30 public ProvideAutomationObjectAttribute(string objectName)
32 if (objectName == null) {
33 throw new ArgumentNullException("ObjectName");
36 name = objectName;
39 /// <include file='doc\ProvideAutomationAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute.Name"]' />
40 /// <devdoc>
41 /// Returns the name of the automation object declared in this attribute.
42 /// </devdoc>
43 public string Name {
44 get {
45 return name;
49 /// <include file='doc\ProvideAutomationObjectAttribute.uex' path='docs/doc[@for="ProvideAutomationObjectAttribute.Description"]' />
50 /// <devdoc>
51 /// The description of the automation object declared in this attribute.
52 /// </devdoc>
53 public string Description
55 get {
56 return description;
58 set {
59 description = value;
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"]' />
69 /// <devdoc>
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.
73 ///
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.
76 /// </devdoc>
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"]' />
87 /// <devdoc>
88 /// Removes the registration information from the registration context.
89 /// </devdoc>
90 public override void Unregister(RegistrationContext context)
92 context.RemoveKey(GetAutomationRegKey(context.ComponentType.GUID));