1
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace BITKit
|
||||
using System;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IOptional
|
||||
{
|
||||
@@ -9,6 +11,7 @@
|
||||
{
|
||||
bool Allow { get; set; }
|
||||
T Value { get; set; }
|
||||
T IfNotAllow(T value);
|
||||
}
|
||||
[System.Serializable]
|
||||
public class Optional<T> : IOptional<T>
|
||||
@@ -29,6 +32,15 @@
|
||||
set=>this.value=value;
|
||||
}
|
||||
|
||||
public T IfNotAllow(T other)
|
||||
{
|
||||
return Allow ? Value : other;
|
||||
}
|
||||
public T IfNotAllow(Func<T> other)
|
||||
{
|
||||
return Allow ? Value : other.Invoke();
|
||||
}
|
||||
|
||||
public void SetValueThenAllow(T newValue)
|
||||
{
|
||||
value = newValue;
|
||||
|
Reference in New Issue
Block a user