mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
Port more things!
This commit is contained in:
parent
f6fb8204bb
commit
47b16dc51b
26 changed files with 332 additions and 186 deletions
32
Myriad/Utils/Optional.cs
Normal file
32
Myriad/Utils/Optional.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Serialization;
|
||||
|
||||
namespace Myriad.Utils
|
||||
{
|
||||
public interface IOptional
|
||||
{
|
||||
bool HasValue { get; }
|
||||
object? GetValue();
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(OptionalConverter))]
|
||||
public readonly struct Optional<T>: IOptional
|
||||
{
|
||||
public Optional(T value)
|
||||
{
|
||||
HasValue = true;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public bool HasValue { get; }
|
||||
public object? GetValue() => Value;
|
||||
|
||||
public T Value { get; }
|
||||
|
||||
public static implicit operator Optional<T>(T value) => new(value);
|
||||
|
||||
public static Optional<T> Some(T value) => new(value);
|
||||
public static Optional<T> None() => default;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue