GlobalVariableId.cs 985 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace FF8
  3. {
  4. public struct GlobalVariableId<T> where T : unmanaged
  5. {
  6. public static String TypeName { get; } = typeof(T).Name;
  7. public static Boolean IsValid = Validate();
  8. public Int32 VariableId { get; }
  9. public GlobalVariableId(Int32 variableId)
  10. {
  11. if (variableId < 0)
  12. throw new ArgumentOutOfRangeException(nameof(variableId), $"Invalid global variable id: {variableId}");
  13. VariableId = variableId;
  14. }
  15. public override String ToString()
  16. {
  17. return $"Global({TypeName}): {VariableId}";
  18. }
  19. public static Boolean Validate()
  20. {
  21. unsafe
  22. {
  23. if (sizeof(T) > 8)
  24. throw new NotSupportedException($"The global variable must be an integer and cannot exceed 8 bytes. {TypeName} isn't supported.");
  25. }
  26. return true;
  27. }
  28. }
  29. }