LSEntityRef.cs 869 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. namespace ET
  2. {
  3. public readonly struct LSEntityRef<T> where T: LSEntity
  4. {
  5. private readonly long id;
  6. private readonly T entity;
  7. private LSEntityRef(T t)
  8. {
  9. this.id = t.Id;
  10. this.entity = t;
  11. }
  12. private T UnWrap
  13. {
  14. get
  15. {
  16. if (this.entity == null)
  17. {
  18. return null;
  19. }
  20. if (this.entity.Id != this.id)
  21. {
  22. return null;
  23. }
  24. return this.entity;
  25. }
  26. }
  27. public static implicit operator LSEntityRef<T>(T t)
  28. {
  29. return new LSEntityRef<T>(t);
  30. }
  31. public static implicit operator T(LSEntityRef<T> v)
  32. {
  33. return v.UnWrap;
  34. }
  35. }
  36. }