Pull to refresh

Разработка редактора (расширение на C# для Visual Studio)

День добрый.


В связи с созданием большого расширяемого проекта, возникла необходимость дать разработчикам возможность собирать свои пакеты/модули под проект. (Нечто похожее на редактор Feature и WSP Package для SharePoint) Для этого необходимо создать редактор пакетов/модулей для Visual Studio. Для создания расширения под Visual Studio очень мало информации в интернете, а из официального нашел только это. Решил собрать свою библиотеку (VSExtensibilityHelper), которая бы облегчила пользователю создание VSIX дополнений. В ней собраны базовые классы для создания редакторов:


  • BaseEditorFactory — Базовый класс фабрика
  • BaseWinFormsEditorPane — Базовый класс для редактора на основе WinForms компонента
  • BaseWpfEditorPane — Базовый класс для редактора на основе WPF компонента

Пример реализации:


[Guid("21411E52-A07A-4304-A162-8C87FD7056EA")]
public sealed class WinFormsEditorFactory : BaseEditorFactory<WinFormsEditorEditorPane>
{
}

public class WinFormsEditorEditorPane : BaseWinFormsEditorPane<WinFormsEditorFactory, Controls.WinForms.WinFormUserControl>
{
  #region Methods

        protected override string GetFileExtension()
        {
            return ".win";
        }

        protected override void LoadFile(string fileName)
        {         
        }

        protected override void SaveFile(string fileName)
        {           
        }     

   #endregion Methods
}

Регистрация пакета:


 [ProvideEditorExtension(typeof(Editors.WinFormsEditorFactory), ".win", 50,
      ProjectGuid = "7D346946-3421-48C0-A98A-20790CB68B3C", NameResourceID = 133,
      TemplateDir = @".\NullPath")]
public sealed class VSPackageCustomEditors : Package
{
    protected override void Initialize()
    {
        base.Initialize();

            /*
             * Registering editor with WinForms control
             * *.win
             */
            base.RegisterEditorFactory(new Editors.WinFormsEditorFactory()); 
    }
}

В данном примере мы создали свой редактор для Visual Studio который запускается при открытии файлов *.win.


Результат:


image


Результат для WPF


image


Ссылка на исходники и пример.


Спасибо всем!

Tags:
Hubs:
You can’t comment this publication because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author’s username will be hidden by an alias.