Advertisement
FrayxRulez

Untitled

Mar 22nd, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. using Microsoft.VisualStudio.Shell;
  2. using System;
  3. using System.Globalization;
  4.  
  5. namespace BandStudio
  6. {
  7. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
  8. public sealed class ExtensionRegistrationAttribute : RegistrationAttribute
  9. {
  10. private string _fileExtension;
  11. private string _projectGuid;
  12. private string _buildAction;
  13. private string _customTool;
  14.  
  15. public ExtensionRegistrationAttribute(string fileExtension, string projectGuid)
  16. {
  17. if (fileExtension == null)
  18. throw new ArgumentNullException("fileExtension");
  19. if (projectGuid == null)
  20. throw new ArgumentNullException("projectGuid");
  21.  
  22. _fileExtension = fileExtension;
  23. _projectGuid = projectGuid;
  24. }
  25.  
  26. public string FileExtension
  27. {
  28. get { return _fileExtension; }
  29. }
  30.  
  31. public string ProjectGuid
  32. {
  33. get { return _projectGuid; }
  34. }
  35.  
  36. public string DefaultBuildAction
  37. {
  38. get { return _buildAction; }
  39. set { _buildAction = value; }
  40. }
  41.  
  42. public string CustomTool
  43. {
  44. get { return _customTool; }
  45. set { _customTool = value; }
  46. }
  47.  
  48. private string GeneratorRegKey
  49. {
  50. get { return string.Format(CultureInfo.InvariantCulture, @"Projects\{0}\FileExtensions\{1}", ProjectGuid, FileExtension); }
  51. }
  52.  
  53. /// <summary>
  54. /// Called to register this attribute with the given context. The context
  55. /// contains the location where the registration inforomation should be placed.
  56. /// It also contains other information such as the type being registered and path information.
  57. /// </summary>
  58. public override void Register(RegistrationContext context)
  59. {
  60. using (Key childKey = context.CreateKey(GeneratorRegKey))
  61. {
  62. if (DefaultBuildAction != null)
  63. childKey.SetValue("DefaultBuildAction", DefaultBuildAction);
  64.  
  65. if (CustomTool != null)
  66. childKey.SetValue("CustomTool", CustomTool);
  67. }
  68. }
  69.  
  70. /// <summary>
  71. /// Unregister this file extension.
  72. /// </summary>
  73. /// <param name="context"></param>
  74. public override void Unregister(RegistrationContext context)
  75. {
  76. context.RemoveKey(GeneratorRegKey);
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement