EditorFactoryNotifyForProjectAttribute.cs :  » Development » StyleCop » Microsoft » VisualStudio » Shell » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Shell » EditorFactoryNotifyForProjectAttribute.cs
//***************************************************************************
//
//    Copyright (c) Microsoft Corporation. All rights reserved.
//    This code is licensed under the Visual Studio SDK license terms.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//***************************************************************************

using System;
using System.Globalization;

namespace Microsoft.VisualStudio.Shell{
    /// <summary>
    /// This attribute adds a File Extension for a Project System so that the Project
    /// will call IVsEditorFactoryNotify methods when an item of this type is added 
    /// or renamed.
    /// </summary>
    /// <remarks>
    /// For example:
    ///   [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Projects\
    ///    {F184B08F-C81C-45F6-A57F-5ABD9991F28F}\FileExtensions\.addin]
    ///      "EditorFactoryNotify"="{FA3CD31E-987B-443A-9B81-186104E8DAC1}"
    /// </remarks>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
    [System.Runtime.InteropServices.ComVisibleAttribute(false)]
    public sealed class EditorFactoryNotifyForProjectAttribute : RegistrationAttribute
    {
        #region Fields
    private Guid projectType;
    private Guid factoryType;
    private string fileExtension;
        #endregion

        #region Constructors
        /// <summary>
        /// Creates a new ProvideEditorFactoryNotifyForProject attribute to register a 
        /// file extension with a project. 
        /// </summary>
        /// <param name="projectType">The type of project; can be a Type, a GUID or a string representation of a GUID</param>
        /// <param name="factoryType">The type of factory; can be a Type, a GUID or a string representation of a GUID</param>
        /// <param name="fileExtension">The file extension the EditorFactoryNotify wants to handle</param>
        public EditorFactoryNotifyForProjectAttribute(object projectType, string fileExtension, object factoryType)
        {
            if (factoryType == null)
            {
                throw new ArgumentNullException("factoryType", "Factory type can not be null.");
            }
            if (projectType == null)
            {
                throw new ArgumentNullException("projectType", "Project type can not be null.");
            }

            this.fileExtension = fileExtension;

            // figure out what type of object they passed in and get the GUID from it
            if (factoryType is string)
            {
                this.factoryType = new Guid(factoryType.ToString());
            }
            else if (factoryType is Type)
            {
                this.factoryType = ((Type)factoryType).GUID;
            }
            else if (factoryType is Guid)
            {
                this.factoryType = (Guid)factoryType;
            }
            else
            {
                throw new ArgumentException( "Parameter is expected to be an instance of the type 'Type' or 'Guid'.", "factoryType");
            }

            // figure out what type of object they passed in and get the GUID from it
            if (projectType is string)
            {
                this.projectType = new Guid(projectType.ToString());
            }
      else if (projectType is Type)
      {
                this.projectType = ((Type)projectType).GUID;
      }
      else if (projectType is Guid)
            {
                this.projectType = (Guid)projectType;
            }
            else
            {
                throw new ArgumentException("Parameter is expected to be an instance of the type 'Type' or 'Guid'.", "projectType");
            }
        }
        #endregion

        #region Properties
        /// <summary>
        /// Get the Guid representing the type of the editor factory
        /// </summary>
        //public Guid FactoryType
        public object FactoryType
        {
            get { return factoryType; }
        }

        /// <summary>
        /// Get the Guid representing the project type
        /// </summary>
        public object ProjectType
        {
            get { return projectType; }
        }

        /// <summary>
        /// Get or Set the extension of the XML files that support this view
        /// </summary>
        public string FileExtension
        {
            get { return fileExtension; }
        }

        /// <summary>
        /// Extention path within the registration context
        /// </summary>
        private string ProjectFileExtensionPath
        {
            get 
            { 
                return string.Format(CultureInfo.InvariantCulture, "Projects\\{0}\\FileExtensions\\{1}", projectType.ToString("B"), fileExtension); 
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Called to register this attribute with the given context.  The context
        /// contains the location where the registration information should be placed.
        /// It also contains other information such as the type being registered and path information.
        /// </summary>
        /// <param name="context">Given context to register in</param>
        public override void Register(RegistrationContext context)
        {
            if (context == null)
            {
              throw new ArgumentNullException("context");
            }

            context.Log.WriteLine(String.Format(CultureInfo.CurrentCulture, "EditorFactoryNoftifyForProject: {0} Extension = {1}\n", projectType.ToString(), fileExtension));

            using (Key childKey = context.CreateKey(ProjectFileExtensionPath))
            {
                childKey.SetValue("EditorFactoryNotify", factoryType.ToString("B"));
            }
        }

        /// <summary>
        /// Unregister this file extension.
        /// </summary>
        /// <param name="context">Given context to unregister from</param>
        public override void Unregister(RegistrationContext context)
        {
            if (context != null)
            {
                context.RemoveKey(ProjectFileExtensionPath);
            }
        }
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.