Class JsonSettingsAutosaveExtensions
- Namespace
- Nucs.JsonSettings.Autosave
- Assembly
- Nucs.JsonSettings.Autosave.dll
public static class JsonSettingsAutosaveExtensions
- Inheritance
-
JsonSettingsAutosaveExtensions
- Inherited Members
Properties
RequireWeaveMarker
When true (the default), EnableAutosave<TSettings>(TSettings) refuses a settings class that carries [Autosave] without carrying the IAutosaveWoven mixin the weave stamps -- the signature of a build that silently skipped AspectInjector, which would otherwise "enable" an autosave that never writes a byte.
public static bool RequireWeaveMarker { get; set; }
Property Value
Remarks
The one legitimate reason to turn this off: an assembly woven by Nucs.JsonSettings.Autosave OLDER than 2.3.0 running against this version of the runtime without a rebuild (a diamond dependency). Those assemblies are genuinely woven -- the old aspect just stamped no marker -- and the advice they carry calls the same OnPropertySet(object, string) and works. Set this to false once at startup for that mix; everything else about validation stays on.
Methods
EnableAutosave<TSettings>(TSettings)
Enables automatic saving when changing any property of a class marked AutosaveAttribute.
public static TSettings EnableAutosave<TSettings>(this TSettings settings) where TSettings : JsonSettings
Parameters
settingsTSettingsThe settings instance to enable autosaving on.
Returns
- TSettings
settingsitself. Unlike the previous Castle-based implementation this is neither a proxy nor a copy -- the returned reference is the one that was passed in, so every other reference to the same instance autosaves too.
Type Parameters
TSettingsA settings class implementing JsonSettings
Exceptions
- JsonSettingsException
When
TSettingsis not marked AutosaveAttribute.
EnableIAutosave<TSettings, ISettings>(TSettings)
Enables automatic saving and returns the settings as ISettings.
public static ISettings EnableIAutosave<TSettings, ISettings>(this TSettings settings) where TSettings : JsonSettings, ISettings where ISettings : class
Parameters
settingsTSettingsThe settings instance to enable autosaving on.
Returns
- ISettings
The instance, as the requested interface.
Type Parameters
TSettingsThe JsonSettings type
ISettingsAn interface your JsonSettings class implements
Remarks
Retained for source compatibility. Under Castle this built a genuinely different object -- an interface proxy forwarding to the original -- which was the only way to intercept a class whose properties were not virtual. Weaving rewrites the setters themselves, so the interface buys nothing beyond the cast and EnableAutosave<TSettings>(TSettings) is now equivalent and clearer.
Exceptions
- JsonSettingsException
When
TSettingsis not marked AutosaveAttribute.
SuspendAutosave<TSettings>(TSettings)
Suspends auto-saving until SuspendAutosave.Dispose or SuspendAutosave.Resume are called.
If changes are introduced while suspension then a save will be commited and resume or disposal.
public static SuspendAutosave SuspendAutosave<TSettings>(this TSettings settings) where TSettings : JsonSettings
Parameters
settingsTSettings
Returns
- SuspendAutosave
A suspend state tracker that can be Disposed for a using block
Type Parameters
TSettings
Remarks
Resolves the shared SuspensionModule base, which finds whichever module the instance carries: the woven path's AutosaveModule or the SettingsBagAutosaveModule a SettingsBag attaches -- so a bag suspends through this same extension without either package knowing the other's concrete type.