Table of Contents

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

bool

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

settings TSettings

The settings instance to enable autosaving on.

Returns

TSettings

settings itself. 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

TSettings

A settings class implementing JsonSettings

Exceptions

JsonSettingsException

When TSettings is 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

settings TSettings

The settings instance to enable autosaving on.

Returns

ISettings

The instance, as the requested interface.

Type Parameters

TSettings

The JsonSettings type

ISettings

An 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 TSettings is 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

settings TSettings

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.