PersistableHelper

Ecng.Serialization

Provides helper methods for persisting, cloning, loading and saving objects.

Métodos

ApplyAsync``1
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 asynchronous persistable object.

obj
The target object.
clone
The object from which to copy the state.
cancellationToken
A token for cancellation.

Devuelve: A ValueTask representing the asynchronous operation.

Apply``1
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.
CloneAsync``1
public static ValueTask<T> CloneAsync<T>(T obj, CancellationToken cancellationToken)
result = PersistableHelper.CloneAsync(obj, cancellationToken)

Asynchronously clones the specified asynchronous persistable object.

obj
The object to clone.
cancellationToken
A token for cancellation.

Devuelve: A ValueTask with the cloned object.

Clone``1
public static T Clone<T>(T obj)
result = PersistableHelper.Clone(obj)

Clones the specified persistable object.

obj
The object to clone.

Devuelve: A clone of the object.

ForceLoad``1
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.
FromStorage
public static object FromStorage(SettingsStorage storage)
result = PersistableHelper.FromStorage(storage)

Converts the settings storage back to an object.

storage
The settings storage.

Devuelve: The object represented by the settings storage.

IsPersistable
public static bool IsPersistable(Type type)
result = PersistableHelper.IsPersistable(type)

Determines whether the specified type is persistable.

type
The type to evaluate.

Devuelve: true if the type implements IPersistable or IAsyncPersistable; otherwise, false.

IsSerializablePrimitive
public static bool IsSerializablePrimitive(Type type)
result = PersistableHelper.IsSerializablePrimitive(type)

Determines whether the specified type is a serializable primitive.

type
The type to examine.

Devuelve: true if the type is a primitive or Uri; otherwise, false.

Load
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.

Devuelve: The loaded persistable object.

Load
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.
LoadAsync
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.

Devuelve: A ValueTask with the loaded asynchronous persistable object.

LoadAsync``1
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.

Devuelve: A ValueTask with the loaded object of type T.

LoadEntire``1
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.

Devuelve: The created and initialized object.

LoadFromString
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.
LoadFromString``1
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.

Devuelve: The deserialized value.

LoadIfNotNull
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.

Devuelve: true if the state was loaded; otherwise, false.

LoadIfNotNull
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.

Devuelve: true if the state was loaded; otherwise, false.

Load``1
public static T Load<T>(SettingsStorage storage)
result = PersistableHelper.Load(storage)

Loads an IPersistable object of type T from the settings storage.

storage
The settings storage to load from.

Devuelve: The loaded object of type T.

RegisterAdapterType
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.
RegisterCustomSerializer``1
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.
RemoveAdapterType
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.

Devuelve: true if the adapter was removed; otherwise, false.

Save
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.

Devuelve: A settings storage containing the saved state.

SaveAsync
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.

Devuelve: A ValueTask with the settings storage containing the saved state.

SaveEntire
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.

Devuelve: A settings storage containing the saved state.

SaveToString
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.

Devuelve: A string representing the saved state.

SaveToString``1
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.

Devuelve: A string representing the settings.

SetValue
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.
ToMember
public static MemberInfo ToMember(SettingsStorage storage)
result = PersistableHelper.ToMember(storage)

Converts the settings storage to a MemberInfo.

storage
The settings storage to convert.

Devuelve: The converted MemberInfo.

ToMember``1
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.

Devuelve: The converted member of type T.

ToRefFive``5
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.

Devuelve: A RefFive tuple containing the converted values.

ToRefPair``2
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.

Devuelve: A RefPair containing the converted values.

ToRefQuadruple``4
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.

Devuelve: A RefQuadruple containing the converted values.

ToRefTriple``3
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.

Devuelve: A RefTriple containing the converted values.

ToStorage
public static SettingsStorage ToStorage(IRefTuple tuple)
result = PersistableHelper.ToStorage(tuple)

Converts a tuple implementing IRefTuple to a settings storage.

tuple
The tuple to convert.

Devuelve: A settings storage representing the tuple.

ToStorage
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.

Devuelve: A settings storage representing the object.

ToStorage``1
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.

Devuelve: A settings storage representing the member.

TryDeserialize``1
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.

Devuelve: true if deserialization was successful; otherwise, false.

TryGetAdapterType
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.

Devuelve: true if found; otherwise, false.

TrySerialize``1
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.

Devuelve: true if serialization was successful; otherwise, false.

UnRegisterCustomSerializer``1
public static void UnRegisterCustomSerializer<T>()
PersistableHelper.UnRegisterCustomSerializer()

Unregisters the custom serializer for a specific type.