IPreferencesService.Save Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Saves the preferences.
public:
void Save();
public void Save ();
abstract member Save : unit -> unit
Public Sub Save ()
Examples
The following example saves and loads the preference store.
class SH {
public static int iCnt;
public static string Count { get { return "Count"; } }
public static string Entry { get { return "Entry"; } }
private static readonly Guid PreferencesKey =
new Guid("{1abb6907-6dff-1638-8323-deadbeef1638}");
private void LoadPreferences2() {
IPreferencesService preferences = (IPreferencesService)
_serviceProvider.GetService(typeof(IPreferencesService));
PreferencesStore store;
bool bExists = preferences.GetPreferencesStore(PreferencesKey, out store);
if (!bExists) {
return;
}
for (int i = 0; i < _features.Length; i++) {
MRUList<MRUPageInfo> current = _features[i];
string val = SH.Count + i.ToString();
int count = (int)store.GetValue(val, 0);
if (count <= 0) {
continue;
}
for (int j = count - 1; j >= 0; j--) {
val = SH.Entry + i.ToString() + "-" + j.ToString();
string modulePageTypeName = store.GetValue(val, null);
current.Add(new MRUPageInfo(modulePageTypeName));
}
}
}
/// <summary>
/// Store the list of features in the preference store using
/// the PreferencesServices.
/// </summary>
internal void SavePreferences() {
if (_serviceProvider != null) {
IPreferencesService preferences = (IPreferencesService)
_serviceProvider.GetService(typeof(IPreferencesService));
PreferencesStore store =
preferences.GetPreferencesStore(PreferencesKey);
for (int i = 0; i < _features.Length; i++) {
MRUList<MRUPageInfo> current = _features[i];
string val = SH.Count + i.ToString();
store.SetValue(val, current.Count, 0);
int j = 0;
foreach (MRUPageInfo info in current) {
if (info == null) {
continue;
}
val = SH.Entry + i.ToString() + "-" + j.ToString();
store.SetValue(val, info.Type, null);
j++;
}
}
preferences.Save();
}
_serviceProvider = null;
}