feature: document handlers
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Disco
|
||||
{
|
||||
@@ -26,4 +28,61 @@ namespace Disco
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class OneOf
|
||||
{
|
||||
public static OneOf<T> Create<T>(T instance)
|
||||
=> OneOf<T>.Create(instance);
|
||||
}
|
||||
public struct OneOf<T> : IEnumerable<T>
|
||||
{
|
||||
private readonly T instance;
|
||||
|
||||
private OneOf(T instance)
|
||||
{
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static OneOf<T> Create(T instance)
|
||||
=> new OneOf<T>(instance);
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
=> new OneOfEnumerator(instance);
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> new OneOfEnumerator(instance);
|
||||
|
||||
private struct OneOfEnumerator : IEnumerator<T>
|
||||
{
|
||||
private readonly T instance;
|
||||
private bool moved;
|
||||
|
||||
public OneOfEnumerator(T instance)
|
||||
{
|
||||
this.instance = instance;
|
||||
moved = false;
|
||||
}
|
||||
|
||||
public T Current => instance;
|
||||
|
||||
object IEnumerator.Current => instance;
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (!moved)
|
||||
{
|
||||
moved = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
moved = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user