Class GeneratedStore
A class providing an extension for Config to make it easy to use generated config stores.
Inherited Members
Namespace: IPA.Config.Stores
Assembly: IPA.Loader.dll
Syntax
public static class GeneratedStore
Fields
| Improve this Doc View SourceAssemblyVisibilityTarget
The name of the assembly that internals must be visible to to allow internal protection.
Declaration
public const string AssemblyVisibilityTarget = "IPA.Config.Generated"
Field Value
Type | Description |
---|---|
String |
Methods
| Improve this Doc View SourceCreate<T>()
Creates a generated store outside of the context of the config system.
Declaration
public static T Create<T>()
where T : class
Returns
Type | Description |
---|---|
T | a generated instance of |
Type Parameters
Name | Description |
---|---|
T | the type to wrap |
Remarks
See Generated<T>(Config, Boolean) for more information about how it behaves.
See Also
| Improve this Doc View SourceGenerated<T>(Config, Boolean)
Creates a generated IConfigStore of type T
, registers it to
the Config object, and returns it. This also forces a synchronous config load via
LoadSync() if loadSync
is true.
Declaration
public static T Generated<T>(this Config cfg, bool loadSync = true)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Config | cfg | the Config to register to |
Boolean | loadSync | whether to synchronously load the content, or trigger an async load |
Returns
Type | Description |
---|---|
T | a generated instance of |
Type Parameters
Name | Description |
---|---|
T | the type to wrap |
Remarks
T
must be a public non-sealed class.
It can also be internal, but in that case, then your assembly must have the following attribute
to allow the generated code to reference it.
[assembly: InternalsVisibleTo(IPA.Config.Stores.GeneratedStore.AssemblyVisibilityTarget)]
Only fields and properties that are public or protected will be considered, and only properties where both the getter and setter are public or protected are considered. Any fields or properties with an IgnoreAttribute applied to them are also ignored. Having properties be virtual is not strictly necessary, however it allows the generated type to keep track of changes and lock around them so that the config will auto-save.
All of the attributes in the IPA.Config.Stores.Attributes namespace are handled as described by them.
If the T
declares a public or protected, virtual
method Changed()
, then that method may be called to artificially signal to the runtime that the content of the object
has changed. That method will also be called after the write locks are released when a property is set anywhere in the owning
tree. This will only be called on the outermost generated object of the config structure, even if the change being signaled
is somewhere deep into the tree. TODO: is this a good idea?
Similarly, T
can declare a public or protected, virtual
method OnReload()
, which will be called on the filesystem reader thread after the object has been repopulated with new data
values. It will be called after the write lock for this object is released. This will only be called on the outermost generated
object of the config structure.
Similarly, T
can declare a public or protected, virtual
method CopyFrom(ConfigType)
(the first parameter is the type it is defined on), which may be called to copy the properties from
another object of its type easily, and more importantly, as only one change. Its body will be executed after the values have been copied.
Similarly, T
can declare a public or protected, virtual
method ChangeTransaction()
returning IDisposable, which may be called to get an object representing a transactional
change. This may be used to change a lot of properties at once without triggering a save multiple times. Ideally, this is used in a
langword_csharp_using block or declaration. The IDisposable returned from your implementation will have its
Dispose() called after Changed()
is called, but before the write lock is released.
Unless you have a very good reason to use the nested IDisposable, avoid it.
If T
is marked with NotifyPropertyChangesAttribute, the resulting object will implement
INotifyPropertyChanged. Similarly, if T
implements INotifyPropertyChanged,
the resulting object will implement it and notify it too.