1
This commit is contained in:
40
Core/Optional/Optional.cs
Normal file
40
Core/Optional/Optional.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IOptional
|
||||
{
|
||||
bool Allow { get; }
|
||||
object Value { get; }
|
||||
}
|
||||
public interface IOptional<T>
|
||||
{
|
||||
bool Allow { get; }
|
||||
T Value { get; }
|
||||
}
|
||||
[System.Serializable]
|
||||
public record Optional<T> : IOptional<T>
|
||||
{
|
||||
#if UNITY
|
||||
[UnityEngine.SerializeField]
|
||||
bool allow;
|
||||
[UnityEngine.SerializeField]
|
||||
T value;
|
||||
#else
|
||||
bool allow;
|
||||
T value;
|
||||
#endif
|
||||
public bool Allow { get => allow; set => allow = value;}
|
||||
public T Value { get => value; set => this.value = value; }
|
||||
public void SetValueThenAllow(T newValue) => value = newValue;
|
||||
public void Clear()
|
||||
{
|
||||
Allow = false;
|
||||
value = default;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user