MaybeNull.cs 563 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. namespace DwarfCorp
  3. {
  4. public struct MaybeNull<T> where T: class
  5. {
  6. private T _Value;
  7. public MaybeNull(T _Value)
  8. {
  9. this._Value = _Value;
  10. }
  11. public static implicit operator MaybeNull<T>(T _Value)
  12. {
  13. return new MaybeNull<T>(_Value);
  14. }
  15. public bool HasValue(out T Value)
  16. {
  17. Value = _Value;
  18. return _Value != null;
  19. }
  20. public bool HasValue()
  21. {
  22. return _Value != null;
  23. }
  24. }
  25. }