Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualStudio.Shell;
- using System;
- using System.Globalization;
- namespace BandStudio
- {
- [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
- public sealed class ExtensionRegistrationAttribute : RegistrationAttribute
- {
- private string _fileExtension;
- private string _projectGuid;
- private string _buildAction;
- private string _customTool;
- public ExtensionRegistrationAttribute(string fileExtension, string projectGuid)
- {
- if (fileExtension == null)
- throw new ArgumentNullException("fileExtension");
- if (projectGuid == null)
- throw new ArgumentNullException("projectGuid");
- _fileExtension = fileExtension;
- _projectGuid = projectGuid;
- }
- public string FileExtension
- {
- get { return _fileExtension; }
- }
- public string ProjectGuid
- {
- get { return _projectGuid; }
- }
- public string DefaultBuildAction
- {
- get { return _buildAction; }
- set { _buildAction = value; }
- }
- public string CustomTool
- {
- get { return _customTool; }
- set { _customTool = value; }
- }
- private string GeneratorRegKey
- {
- get { return string.Format(CultureInfo.InvariantCulture, @"Projects\{0}\FileExtensions\{1}", ProjectGuid, FileExtension); }
- }
- /// <summary>
- /// Called to register this attribute with the given context. The context
- /// contains the location where the registration inforomation should be placed.
- /// It also contains other information such as the type being registered and path information.
- /// </summary>
- public override void Register(RegistrationContext context)
- {
- using (Key childKey = context.CreateKey(GeneratorRegKey))
- {
- if (DefaultBuildAction != null)
- childKey.SetValue("DefaultBuildAction", DefaultBuildAction);
- if (CustomTool != null)
- childKey.SetValue("CustomTool", CustomTool);
- }
- }
- /// <summary>
- /// Unregister this file extension.
- /// </summary>
- /// <param name="context"></param>
- public override void Unregister(RegistrationContext context)
- {
- context.RemoveKey(GeneratorRegKey);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement