Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ namespace Aspid.MVVM
/// <typeparam name="T">The type of the value to be bound.</typeparam>
public sealed class OneTimeBindableMember<T> : OneTimeBindableMember, IReadOnlyValueBindableMember<T>
{
private static readonly OneTimeBindableMember<T> _instance = new();

/// <summary>
/// Gets or sets the current value.
/// Gets the current value.
/// </summary>
public T? Value { get; private set; }

/// <summary>
/// Gets the binding mode for this member.
/// </summary>
public BindMode Mode => BindMode.OneTime;

private OneTimeBindableMember() { }
private OneTimeBindableMember(T? value)
{
Value = value;
}

/// <inheritdoc />
/// <summary>
Expand Down Expand Up @@ -60,18 +61,17 @@ private OneTimeBindableMember() { }
}

/// <summary>
/// Creates a reusable instance and assigns the provided value for one-time binding.
/// Creates a new instance configured with the provided value for one-time binding.
/// </summary>
/// <param name="value">The value to be provided to the binder.</param>
/// <returns>A singleton instance of <see cref="OneTimeBindableMember{T}"/> configured with the specified value.</returns>
/// <returns>A new <see cref="OneTimeBindableMember{T}"/> instance configured with the specified value.</returns>
public static OneTimeBindableMember<T> Get(T value)
{
#if UNITY_2022_1_OR_NEWER && !ASPID_MVVM_UNITY_PROFILER_DISABLED
using (GetMarker.Auto())
#endif
{
_instance.Value = value;
return _instance;
return new(value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@ namespace Aspid.MVVM
public sealed class OneTimeEnumBindableMember<T> : OneTimeStructBindableMember<T, Enum>
where T : struct, Enum
{
private static readonly OneTimeEnumBindableMember<T> _instance = new();

private OneTimeEnumBindableMember() { }

private OneTimeEnumBindableMember(T value) : base(value) { }

/// <summary>
/// Creates a reusable instance and assigns the provided enum value for one-time binding.
/// Creates a new instance configured with the provided enum value for one-time binding.
/// </summary>
/// <param name="value">The enum value to provide to the binder.</param>
/// <returns>A singleton instance of <see cref="OneTimeEnumBindableMember{T}"/> configured with the specified value.</returns>
/// <returns>A new <see cref="OneTimeEnumBindableMember{T}"/> instance configured with the specified value.</returns>
public static OneTimeEnumBindableMember<T> Get(T value)
{
#if UNITY_2022_1_OR_NEWER && !ASPID_MVVM_UNITY_PROFILER_DISABLED
using (GetMarker.Auto())
#endif
{
_instance.Value = value;
return _instance;
return new(value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@ namespace Aspid.MVVM
public sealed class OneTimeStructBindableMember<T> : OneTimeStructBindableMember<T, ValueType>
where T : struct
{
private static readonly OneTimeStructBindableMember<T> _instance = new();

private OneTimeStructBindableMember() { }

private OneTimeStructBindableMember(T value) : base(value) { }

/// <summary>
/// Creates a reusable instance and assigns the provided value for one-time binding.
/// Creates a new instance configured with the provided value for one-time binding.
/// </summary>
/// <param name="value">The value to be provided to the binder.</param>
/// <returns>A singleton instance of <see cref="OneTimeStructBindableMember{T}"/> configured with the specified value.</returns>
/// <returns>A new <see cref="OneTimeStructBindableMember{T}"/> instance configured with the specified value.</returns>
public static OneTimeStructBindableMember<T> Get(T value)
{
#if UNITY_2022_1_OR_NEWER && !ASPID_MVVM_UNITY_PROFILER_DISABLED
using (GetMarker.Auto())
#endif
#endif
{
_instance.Value = value;
return _instance;
return new(value);
}
}
}
Expand All @@ -41,16 +38,19 @@ public abstract class OneTimeStructBindableMember<T, TBoxed> : OneTimeStructBind
where TBoxed : class
{
/// <summary>
/// Gets or sets the current value.
/// Gets the current value.
/// </summary>
public T Value { get; private protected set; }
public T Value { get; }

/// <summary>
/// Gets the binding mode for this member.
/// </summary>
public BindMode Mode => BindMode.OneTime;

private protected OneTimeStructBindableMember() { }
public BindMode Mode => BindMode.OneTime;

private protected OneTimeStructBindableMember(T value)
{
Value = value;
}

/// <inheritdoc />
/// <summary>
Expand Down
Loading