NeverNull.cs 572 B

1234567891011121314151617181920212223242526
  1. using System;
  2. namespace DwarfCorp
  3. {
  4. public struct NeverNull<T> where T: class
  5. {
  6. private T _Value;
  7. public T Value => _Value;
  8. public NeverNull(T _Value)
  9. {
  10. if (_Value == null) throw new InvalidOperationException();
  11. this._Value = _Value;
  12. }
  13. public static implicit operator NeverNull<T>(T _Value)
  14. {
  15. return new NeverNull<T>(_Value);
  16. }
  17. public static implicit operator T(NeverNull<T> _Value)
  18. {
  19. return _Value.Value;
  20. }
  21. }
  22. }