Ecco un breve tutorial potrebbe darti un'idea di come ottenere ciò semplicemente (è abbastanza semplice una volta che l'hai fatto una volta).
Ho derivato il codice seguente da quello che utilizzo in my extensions; è in VB.NET, ma può essere facilmente convertito in C#.
Per iniziare, è sufficiente aggiungere questa classe al progetto di estensione. Dovrebbe contenere una proprietà per ogni valore che è necessario memorizzare. Puoi persino organizzarli in categorie. È possibile avere un aspetto at MSDN here per i tipi supportati (per i casi più complessi si può fare riferimento a "pagine di opzioni personalizzate", che è un argomento coperto by MSDN here).
Imports Microsoft.VisualBasic
Imports System
Imports System.Diagnostics
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.ComponentModel.Design
Imports Microsoft.Win32
Imports Microsoft.VisualStudio
Imports Microsoft.VisualStudio.Shell.Interop
Imports Microsoft.VisualStudio.OLE.Interop
Imports Microsoft.VisualStudio.Shell
Imports System.Threading
Imports System.Text.RegularExpressions
Imports System.ComponentModel
<ClassInterface(ClassInterfaceType.AutoDual)>
<CLSCompliant(False), ComVisible(True)>
Public Class OptionPageGrid
Inherits DialogPage
Private _MyBooleanSetting As Boolean = False
<Category("The name or an alias of my extension name")>
<DisplayName("Simple name of this setting displayed for the user")>
<Description("Longer description of this setting")>
Public Property MyBooleanSetting() As Boolean
Get
Return Me._MyBooleanSetting
End Get
Set(ByVal value As Boolean)
Me._MyBooleanSetting = value
End Set
End Property
Private _MyIntegerSetting As Integer = 2
<Category("The name or an alias of my extension name")>
<DisplayName("Simple name of this setting displayed for the user")>
<Description("Longer description of this setting")>
Public Property MyIntegerSetting() As Integer
Get
Return Me._MyIntegerSetting
End Get
Set(ByVal value As Integer)
Me._MyIntegerSetting = value
End Set
End Property
Private _MyStringSetting As String = "DefaultStringValue"
<Category("The name or an alias of my extension name")>
<DisplayName("Simple name of this setting displayed for the user")>
<Description("Longer description of this setting")>
Public Property MyStringSetting() As Integer
Get
Return Me._MyStringSetting
End Get
Set(ByVal value As Integer)
Me._MyStringSetting = value
End Set
End Property
End Class
Quindi aggiungere i seguenti attributi subito prima della classe del pacchetto principale.
<ProvideOptionPage(GetType(OptionPageGrid), "The name or an alias of my extension name", "The name of a category of settings", 0, 0, True)>
Public NotInheritable Class MyExtensionMainClass
Inherits Package
Ora per accedere con facilità le impostazioni, è possibile aggiungere la seguente proprietà nel Master Class pacchetto:
Protected ReadOnly Property Settings() As OptionPageGrid
Get
Return CType(GetDialogPage(GetType(OptionPageGrid)), OptionPageGrid)
End Get
End Property
In questo modo è possibile accedere a un valore da qualsiasi parte della classe con un amichevole:
If (Me.Settings.MyBooleanSetting) Then MsgBox("It works!");
Visual Studio si prenderà cura di persistenza delle impostazioni, e dovrebbero essere inclusi quando si utilizza la funzione di importazione/esportazione (o qualsiasi estensione impostazioni di sincronizzazione come this one).
È possibile che non sia disponibile poiché è la prima volta che cerco di eseguire questa operazione, ma l'unico modo in cui mi sembra possibile utilizzare il codice più recente consiste nel modificare il tipo di parametro da SVsServiceProvider a IServiceProvider. – jschroedl