PersistableHelper
Provides helper methods for persisting, cloning, loading and saving objects.
メソッド
public static ValueTask ApplyAsync<T>(T obj, T clone, CancellationToken cancellationToken)
result = PersistableHelper.ApplyAsync(obj, clone, cancellationToken)
Asynchronously applies the state from the clone to the target persistable object. The object may be persisted either synchronously or asynchronously.
- obj
- The target object.
- clone
- The object from which to copy the state.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask representing the asynchronous operation.
public static void Apply<T>(T obj, T clone)
PersistableHelper.Apply(obj, clone)
Applies the state from the clone to the target persistable object.
- obj
- The target object.
- clone
- The object from which to copy the state.
public static ValueTask<T> CloneAsync<T>(T obj, CancellationToken cancellationToken)
result = PersistableHelper.CloneAsync(obj, cancellationToken)
Asynchronously clones the specified persistable object. The object may be persisted either synchronously or asynchronously.
- obj
- The object to clone.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask with the cloned object.
public static T Clone<T>(T obj)
result = PersistableHelper.Clone(obj)
Clones the specified persistable object.
- obj
- The object to clone.
戻り値: A clone of the object.
public static void ForceLoad<T>(T t, SettingsStorage storage)
PersistableHelper.ForceLoad(t, storage)
Forces the persistable object to load its state from the given settings storage.
- t
- The target object.
- storage
- The settings storage to load from.
public static object FromStorage(SettingsStorage storage)
result = PersistableHelper.FromStorage(storage)
Converts the settings storage back to an object.
- storage
- The settings storage.
戻り値: The object represented by the settings storage.
public static ValueTask<object> FromStorageAsync(SettingsStorage storage, CancellationToken cancellationToken)
result = PersistableHelper.FromStorageAsync(storage, cancellationToken)
Converts the settings storage back to an object.
- storage
- The settings storage.
- cancellationToken
- A token for cancellation.
戻り値: The object represented by the settings storage.
public static bool IsPersistable(Type type)
result = PersistableHelper.IsPersistable(type)
Determines whether the specified type is persistable.
- type
- The type to evaluate.
戻り値: true if the type implements IPersistable or IAsyncPersistable; otherwise, false.
public static bool IsSerializablePrimitive(Type type)
result = PersistableHelper.IsSerializablePrimitive(type)
Determines whether the specified type is a serializable primitive.
- type
- The type to examine.
戻り値: true if the type is a primitive or Uri; otherwise, false.
public static void Load(IPersistable persistable, SettingsStorage settings, string name)
PersistableHelper.Load(persistable, settings, name)
Loads the state of the persistable object from the specified settings storage using the given key.
- persistable
- The persistable object to load.
- settings
- The settings storage.
- name
- The name of the value within the storage.
public static void Load(IAsyncPersistable persistable, SettingsStorage storage)
PersistableHelper.Load(persistable, storage)
Loads the state of the asynchronously persisted object.
- persistable
- The persistable object to load.
- storage
- The settings storage.
public static IPersistable Load(SettingsStorage storage, Type type)
result = PersistableHelper.Load(storage, type)
Loads an IPersistable object of the specified type from the settings storage.
- storage
- The settings storage to load from.
- type
- The type of the persistable object.
戻り値: The loaded persistable object.
public static void Load(IAsyncPersistable persistable, SettingsStorage settings, string name)
PersistableHelper.Load(persistable, settings, name)
Loads the state of the asynchronously persisted object from the specified settings storage using the given key.
- persistable
- The persistable object to load.
- settings
- The settings storage.
- name
- The name of the value within the storage.
public static ValueTask<T[]> LoadAllAsync<T>(IEnumerable<SettingsStorage> storages, CancellationToken cancellationToken)
result = PersistableHelper.LoadAllAsync(storages, cancellationToken)
Asynchronously loads an object of type T from every settings storage.
- storages
- The settings storages to load from.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask with the loaded objects, in the order of .
public static ValueTask LoadAsync(IAsyncPersistable persistable, SettingsStorage settings, string name, CancellationToken cancellationToken)
result = PersistableHelper.LoadAsync(persistable, settings, name, cancellationToken)
Asynchronously loads the state of the persistable object from the specified settings storage using the given key.
- persistable
- The persistable object to load.
- settings
- The settings storage.
- name
- The name of the value within the storage.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask representing the asynchronous operation.
public static ValueTask<IAsyncPersistable> LoadAsync(SettingsStorage storage, Type type, CancellationToken cancellationToken)
result = PersistableHelper.LoadAsync(storage, type, cancellationToken)
Asynchronously loads an asynchronous persistable object using the specified type.
- storage
- The settings storage to load from.
- type
- The type of the asynchronous persistable object.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask with the loaded asynchronous persistable object.
public static ValueTask<T> LoadAsync<T>(SettingsStorage storage, CancellationToken cancellationToken)
result = PersistableHelper.LoadAsync(storage, cancellationToken)
Asynchronously loads an asynchronous persistable object of type T.
- storage
- The settings storage to load from.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask with the loaded object of type T.
public static ValueTask<T> LoadEntireAsync<T>(SettingsStorage storage, Func<Type, T> create, CancellationToken cancellationToken)
result = PersistableHelper.LoadEntireAsync(storage, create, cancellationToken)
Asynchronously creates an object of the type the settings storage names with and initializes it from the storage. The object may be persisted either synchronously or asynchronously.
- storage
- The settings storage used to create the object.
- create
- Builds the instance of the type the storage names.
- cancellationToken
- A token for cancellation.
戻り値: The created and initialized object.
public static ValueTask<T> LoadEntireAsync<T>(SettingsStorage storage, CancellationToken cancellationToken)
result = PersistableHelper.LoadEntireAsync(storage, cancellationToken)
Asynchronously creates and initializes an object from the settings storage written by CancellationToken) or Boolean). The object may be persisted either synchronously or asynchronously.
- storage
- The settings storage used to create the object.
- cancellationToken
- A token for cancellation.
戻り値: The created and initialized object.
public static T LoadEntire<T>(SettingsStorage storage, Func<Type, T> create)
result = PersistableHelper.LoadEntire(storage, create)
Creates an object of the type the settings storage names with and initializes it from the storage.
- storage
- The settings storage used to create the object.
- create
- Builds the instance of the type the storage names.
戻り値: The created and initialized object.
public static T LoadEntire<T>(SettingsStorage storage)
result = PersistableHelper.LoadEntire(storage)
Creates and initializes an object from the specified settings storage.
- storage
- The settings storage used to create the object.
戻り値: The created and initialized object.
public static void LoadFromString(ISerializer<SettingsStorage> serializer, IAsyncPersistable persistable, string value)
PersistableHelper.LoadFromString(serializer, persistable, value)
Loads the state of the persistable object from a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to load.
- value
- The string representation of the state.
public static void LoadFromString(ISerializer<SettingsStorage> serializer, IPersistable persistable, string value)
PersistableHelper.LoadFromString(serializer, persistable, value)
Loads the state of the persistable object from a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to load.
- value
- The string representation of the state.
public static ValueTask LoadFromStringAsync(ISerializer<SettingsStorage> serializer, IAsyncPersistable persistable, string value, CancellationToken cancellationToken)
result = PersistableHelper.LoadFromStringAsync(serializer, persistable, value, cancellationToken)
Loads the state of the persistable object from a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to load.
- value
- The string representation of the state.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask representing the asynchronous operation.
public static ValueTask LoadFromStringAsync(ISerializer<SettingsStorage> serializer, IPersistable persistable, string value, CancellationToken cancellationToken)
result = PersistableHelper.LoadFromStringAsync(serializer, persistable, value, cancellationToken)
Loads the state of the persistable object from a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to load.
- value
- The string representation of the state.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask representing the asynchronous operation.
public static ValueTask<TValue> LoadFromStringAsync<TValue>(ISerializer<TValue> serializer, string value, CancellationToken cancellationToken)
result = PersistableHelper.LoadFromStringAsync(serializer, value, cancellationToken)
Loads a value of type TValue from a string using the provided serializer.
- serializer
- The serializer to use.
- value
- The string representation of the value.
- cancellationToken
- A token for cancellation.
戻り値: The deserialized value.
public static TValue LoadFromString<TValue>(ISerializer<TValue> serializer, string value)
result = PersistableHelper.LoadFromString(serializer, value)
Loads a value of type TValue from a string using the provided serializer.
- serializer
- The serializer to use.
- value
- The string representation of the value.
戻り値: The deserialized value.
public static bool LoadIfNotNull(IAsyncPersistable persistable, SettingsStorage storage)
result = PersistableHelper.LoadIfNotNull(persistable, storage)
Loads the state of the asynchronously persisted object from the specified settings storage if the storage is not null.
- persistable
- The persistable object to load.
- storage
- The settings storage.
戻り値: true if the state was loaded; otherwise, false.
public static bool LoadIfNotNull(IAsyncPersistable persistable, SettingsStorage settings, string name)
result = PersistableHelper.LoadIfNotNull(persistable, settings, name)
Loads the state of the asynchronously persisted object from the specified settings storage using the given key if it is not null.
- persistable
- The persistable object to load.
- settings
- The settings storage.
- name
- The name of the value within the storage.
戻り値: true if the state was loaded; otherwise, false.
public static bool LoadIfNotNull(IPersistable persistable, SettingsStorage settings, string name)
result = PersistableHelper.LoadIfNotNull(persistable, settings, name)
Loads the state of the persistable object from the specified settings storage using the given key if it is not null.
- persistable
- The persistable object to load.
- settings
- The settings storage.
- name
- The name of the value within the storage.
戻り値: true if the state was loaded; otherwise, false.
public static bool LoadIfNotNull(IPersistable persistable, SettingsStorage storage)
result = PersistableHelper.LoadIfNotNull(persistable, storage)
Loads the state of the persistable object from the specified settings storage if the storage is not null.
- persistable
- The persistable object to load.
- storage
- The settings storage.
戻り値: true if the state was loaded; otherwise, false.
public static ValueTask<bool> LoadIfNotNullAsync(IAsyncPersistable persistable, SettingsStorage storage, CancellationToken cancellationToken)
result = PersistableHelper.LoadIfNotNullAsync(persistable, storage, cancellationToken)
Asynchronously loads the state of the persistable object from the specified settings storage if the storage is not null.
- persistable
- The persistable object to load.
- storage
- The settings storage.
- cancellationToken
- A token for cancellation.
戻り値: true if the state was loaded; otherwise, false.
public static ValueTask<bool> LoadIfNotNullAsync(IAsyncPersistable persistable, SettingsStorage settings, string name, CancellationToken cancellationToken)
result = PersistableHelper.LoadIfNotNullAsync(persistable, settings, name, cancellationToken)
Asynchronously loads the state of the persistable object from the specified settings storage using the given key if it is not null.
- persistable
- The persistable object to load.
- settings
- The settings storage.
- name
- The name of the value within the storage.
- cancellationToken
- A token for cancellation.
戻り値: true if the state was loaded; otherwise, false.
public static T Load<T>(SettingsStorage storage)
result = PersistableHelper.Load(storage)
Loads a persistable object of type T from the settings storage.
- storage
- The settings storage to load from.
戻り値: The loaded object of type T.
public static void RegisterAdapterType(Type type, Type adapterType)
PersistableHelper.RegisterAdapterType(type, adapterType)
Registers the adapter type for the given type.
- type
- The type for which the adapter is registered.
- adapterType
- The adapter type to register.
public static void RegisterCustomSerializer<T>(Func<T, SettingsStorage> serialize, Func<SettingsStorage, T> deserialize)
PersistableHelper.RegisterCustomSerializer(serialize, deserialize)
Registers a custom serializer for a specific type.
- serialize
- A function to serialize the object to a settings storage.
- deserialize
- A function to deserialize from a settings storage to the object.
public static bool RemoveAdapterType(Type type)
result = PersistableHelper.RemoveAdapterType(type)
Removes the registered adapter type for the given type.
- type
- The type whose adapter registration is removed.
戻り値: true if the adapter was removed; otherwise, false.
public static SettingsStorage Save(IAsyncPersistable persistable)
result = PersistableHelper.Save(persistable)
Saves the state of the asynchronously persisted object to a new settings storage.
- persistable
- The persistable object to save.
戻り値: A settings storage containing the saved state.
public static void Save(IAsyncPersistable persistable, SettingsStorage storage)
PersistableHelper.Save(persistable, storage)
Saves the state of the asynchronously persisted object.
- persistable
- The persistable object to save.
- storage
- The settings storage.
public static SettingsStorage Save(IPersistable persistable)
result = PersistableHelper.Save(persistable)
Saves the state of the persistable object to a settings storage.
- persistable
- The persistable object to save.
戻り値: A settings storage containing the saved state.
public static ValueTask<SettingsStorage[]> SaveAllAsync<T>(IEnumerable<T> items, CancellationToken cancellationToken)
result = PersistableHelper.SaveAllAsync(items, cancellationToken)
Asynchronously saves every item into a settings storage of its own.
- items
- The objects to save.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask with the storages, in the order of .
public static ValueTask<SettingsStorage> SaveAsync(IAsyncPersistable persistable, CancellationToken cancellationToken)
result = PersistableHelper.SaveAsync(persistable, cancellationToken)
Asynchronously saves the state of the asynchronous persistable object to a settings storage.
- persistable
- The asynchronous persistable object.
- cancellationToken
- A token for cancellation.
戻り値: A ValueTask with the settings storage containing the saved state.
public static SettingsStorage SaveEntire(IPersistable persistable, bool isAssemblyQualifiedName)
result = PersistableHelper.SaveEntire(persistable, isAssemblyQualifiedName)
Saves the entire state of the persistable object into a new settings storage.
- persistable
- The persistable object to save.
- isAssemblyQualifiedName
- A value indicating whether the type name should be assembly qualified.
戻り値: A settings storage containing the saved state.
public static ValueTask<SettingsStorage> SaveEntireAsync<T>(T persistable, bool isAssemblyQualifiedName, CancellationToken cancellationToken)
result = PersistableHelper.SaveEntireAsync(persistable, isAssemblyQualifiedName, cancellationToken)
Asynchronously saves the entire state of the persistable object, together with its type, into a new settings storage. The object may be persisted either synchronously or asynchronously.
- persistable
- The persistable object to save.
- isAssemblyQualifiedName
- A value indicating whether the type name should be assembly qualified.
- cancellationToken
- A token for cancellation.
戻り値: A settings storage containing the saved state.
public static string SaveToString(ISerializer<SettingsStorage> serializer, IPersistable persistable)
result = PersistableHelper.SaveToString(serializer, persistable)
Saves the state of the persistable object to a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to save.
戻り値: A string representing the saved state.
public static string SaveToString(ISerializer<SettingsStorage> serializer, IAsyncPersistable persistable)
result = PersistableHelper.SaveToString(serializer, persistable)
Saves the state of the persistable object to a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to save.
戻り値: A string representing the saved state.
public static ValueTask<string> SaveToStringAsync(ISerializer<SettingsStorage> serializer, IPersistable persistable, CancellationToken cancellationToken)
result = PersistableHelper.SaveToStringAsync(serializer, persistable, cancellationToken)
Saves the state of the persistable object to a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to save.
- cancellationToken
- A token for cancellation.
戻り値: A string representing the saved state.
public static ValueTask<string> SaveToStringAsync(ISerializer<SettingsStorage> serializer, IAsyncPersistable persistable, CancellationToken cancellationToken)
result = PersistableHelper.SaveToStringAsync(serializer, persistable, cancellationToken)
Saves the state of the persistable object to a string using the provided serializer.
- serializer
- The serializer to use.
- persistable
- The persistable object to save.
- cancellationToken
- A token for cancellation.
戻り値: A string representing the saved state.
public static ValueTask<string> SaveToStringAsync<TValue>(ISerializer<TValue> serializer, TValue settings, CancellationToken cancellationToken)
result = PersistableHelper.SaveToStringAsync(serializer, settings, cancellationToken)
Saves the settings to a string using the provided serializer.
- serializer
- The serializer to use.
- settings
- The settings to save.
- cancellationToken
- A token for cancellation.
戻り値: A string representing the settings.
public static string SaveToString<TValue>(ISerializer<TValue> serializer, TValue settings)
result = PersistableHelper.SaveToString(serializer, settings)
Saves the settings to a string using the provided serializer.
- serializer
- The serializer to use.
- settings
- The settings to save.
戻り値: A string representing the settings.
public static void SetValue(SettingsStorage storage, string name, IPersistable persistable)
PersistableHelper.SetValue(storage, name, persistable)
Adds a persistable object's state as a value in the settings storage.
- storage
- The settings storage to update.
- name
- The name of the setting.
- persistable
- The persistable object whose state is added.
public static MemberInfo ToMember(SettingsStorage storage)
result = PersistableHelper.ToMember(storage)
Converts the settings storage to a MemberInfo.
- storage
- The settings storage to convert.
戻り値: The converted MemberInfo.
public static T ToMember<T>(SettingsStorage storage)
result = PersistableHelper.ToMember(storage)
Converts the settings storage to a member of type T.
- storage
- The settings storage to convert.
戻り値: The converted member of type T.
public static RefFive<T1, T2, T3, T4, T5> ToRefFive<T1, T2, T3, T4, T5>(SettingsStorage storage)
result = PersistableHelper.ToRefFive(storage)
Converts the settings storage to a RefFive tuple of the specified types.
- storage
- The settings storage to convert.
戻り値: A RefFive tuple containing the converted values.
public static RefPair<T1, T2> ToRefPair<T1, T2>(SettingsStorage storage)
result = PersistableHelper.ToRefPair(storage)
Converts the settings storage to a RefPair of the specified types.
- storage
- The settings storage to convert.
戻り値: A RefPair containing the converted values.
public static RefQuadruple<T1, T2, T3, T4> ToRefQuadruple<T1, T2, T3, T4>(SettingsStorage storage)
result = PersistableHelper.ToRefQuadruple(storage)
Converts the settings storage to a RefQuadruple of the specified types.
- storage
- The settings storage to convert.
戻り値: A RefQuadruple containing the converted values.
public static RefTriple<T1, T2, T3> ToRefTriple<T1, T2, T3>(SettingsStorage storage)
result = PersistableHelper.ToRefTriple(storage)
Converts the settings storage to a RefTriple of the specified types.
- storage
- The settings storage to convert.
戻り値: A RefTriple containing the converted values.
public static SettingsStorage ToStorage(object value, bool isAssemblyQualifiedName)
result = PersistableHelper.ToStorage(value, isAssemblyQualifiedName)
Converts an object to a settings storage with type and value.
- value
- The object to convert.
- isAssemblyQualifiedName
- A value indicating whether the type name should be assembly qualified.
戻り値: A settings storage representing the object.
public static SettingsStorage ToStorage(IRefTuple tuple)
result = PersistableHelper.ToStorage(tuple)
Converts a tuple implementing IRefTuple to a settings storage.
- tuple
- The tuple to convert.
戻り値: A settings storage representing the tuple.
public static ValueTask<SettingsStorage> ToStorageAsync(object value, bool isAssemblyQualifiedName, CancellationToken cancellationToken)
result = PersistableHelper.ToStorageAsync(value, isAssemblyQualifiedName, cancellationToken)
Converts an object to a settings storage with type and value.
- value
- The object to convert.
- isAssemblyQualifiedName
- A value indicating whether the type name should be assembly qualified.
- cancellationToken
- A token for cancellation.
戻り値: A settings storage representing the object.
public static SettingsStorage ToStorage<T>(T member, bool isAssemblyQualifiedName)
result = PersistableHelper.ToStorage(member, isAssemblyQualifiedName)
Converts the specified member to a settings storage.
- member
- The member to convert.
- isAssemblyQualifiedName
- A value indicating whether the type name should be assembly qualified.
戻り値: A settings storage representing the member.
public static bool TryDeserialize<T>(SettingsStorage storage, T value)
result = PersistableHelper.TryDeserialize(storage, value)
Tries to deserialize a settings storage into an object of type T using a registered custom serializer.
- storage
- The settings storage containing serialized data.
- value
- When this method returns, contains the deserialized object if successful.
戻り値: true if deserialization was successful; otherwise, false.
public static bool TryGetAdapterType(Type type, Type adapterType)
result = PersistableHelper.TryGetAdapterType(type, adapterType)
Tries to get the registered adapter type for the given type.
- type
- The type to check.
- adapterType
- When this method returns, contains the adapter type if found.
戻り値: true if found; otherwise, false.
public static bool TrySerialize<T>(T value, SettingsStorage storage)
result = PersistableHelper.TrySerialize(value, storage)
Tries to serialize an object using a registered custom serializer.
- value
- The object to serialize.
- storage
- When this method returns, contains the resulting settings storage if serialization was successful.
戻り値: true if serialization was successful; otherwise, false.
public static void UnRegisterCustomSerializer<T>()
PersistableHelper.UnRegisterCustomSerializer()
Unregisters the custom serializer for a specific type.