Ejemplo n.º 1
0
        /// <summary>
        /// Init constructor.
        /// </summary>
        public CustomAddInManager(DTE2 applicationObject, AddIn addInInst, IMenuCustomizator menuCustomizator, Assembly assemblyForSatellites)
        {
            appObject     = applicationObject;
            addInInstance = addInInst;
            actions       = new CustomAddInActionDictionary();
            menuManager   = new CustomAddInMenuManager(applicationObject, addInInst, menuCustomizator);
            assist        = new PackageAssist(this);
            mainAssembly  = assemblyForSatellites;

            selectionContainer = new Microsoft.VisualStudio.Shell.SelectionContainer();
            selectedItems      = new System.Collections.ArrayList();
            selectedElements   = new object[1];

            // all settings read/writes will be pefrom according current version of Visual Studio IDE:
            PersistentStorageHelper.Attach(applicationObject);
            BaseOptionPage.ConfigProvider = this;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all available refactoring options generated by automatically scanning of currently executed assembly.
        /// </summary>
        public static CustomAddInActionDictionary AutoDiscoverRefactorOptions(params Assembly[] assemblies)
        {
            try
            {
                CustomAddInActionDictionary dict = new CustomAddInActionDictionary();
                Type generalType = typeof(IPackageAction);

                foreach (Assembly a in assemblies)
                {
                    Type[] availableTypes = a.GetTypes();

                    foreach (Type type in availableTypes)
                    {
                        if (!type.IsAbstract && generalType.IsAssignableFrom(type))
                        {
                            try
                            {
                                // store for future usage:
                                dict.Add(Activator.CreateInstance(type) as IPackageAction);
                            }
                            catch (TargetInvocationException e)
                            {
                                Trace.TraceError(e.ToString());
                            }
                            catch (ArgumentException e)
                            {
                                Trace.TraceError(e.ToString());
                            }
                            catch (MissingMethodException e)
                            {
                                Trace.TraceError(e.ToString());
                            }
                        }
                    }
                }

                return(dict);
            }
            catch (Exception e)
            {
                Trace.TraceError(e.ToString());
                throw;
            }
        }