You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. using System;
  2. namespace IPA
  3. {
  4. internal enum EdgeLifecycleType
  5. {
  6. Enable, Disable
  7. }
  8. internal interface IEdgeLifecycleAttribute
  9. {
  10. EdgeLifecycleType Type { get; }
  11. }
  12. // TODO: is there a better way to manage this mess?
  13. /// <summary>
  14. /// Indicates that the target method should be called when the plugin is enabled.
  15. /// </summary>
  16. /// <remarks>
  17. /// <para>
  18. /// This attribute is interchangable with <see cref="OnStartAttribute"/>, and is treated identically.
  19. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  20. /// </para>
  21. /// <para>
  22. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  23. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.DynamicInit"/>.
  24. /// </para>
  25. /// </remarks>
  26. /// <seealso cref="PluginAttribute"/>
  27. /// <seealso cref="OnStartAttribute"/>
  28. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  29. public sealed class OnEnableAttribute : Attribute, IEdgeLifecycleAttribute
  30. {
  31. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Enable;
  32. }
  33. /// <summary>
  34. /// Indicates that the target method should be called when the game starts.
  35. /// </summary>
  36. /// <remarks>
  37. /// <para>
  38. /// This attribute is interchangable with <see cref="OnEnableAttribute"/>, and is treated identically.
  39. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  40. /// </para>
  41. /// <para>
  42. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  43. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.SingleStartInit"/>.
  44. /// </para>
  45. /// </remarks>
  46. /// <seealso cref="PluginAttribute"/>
  47. /// <seealso cref="OnEnableAttribute"/>
  48. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  49. public sealed class OnStartAttribute : Attribute, IEdgeLifecycleAttribute
  50. {
  51. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Enable;
  52. }
  53. /// <summary>
  54. /// Indicates that the target method should be called when the plugin is disabled.
  55. /// </summary>
  56. /// <remarks>
  57. /// <para>
  58. /// This attribute is interchangable with <see cref="OnExitAttribute"/>, and is treated identically.
  59. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  60. /// </para>
  61. /// <para>
  62. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  63. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.DynamicInit"/>.
  64. /// </para>
  65. /// </remarks>
  66. /// <seealso cref="PluginAttribute"/>
  67. /// <seealso cref="OnExitAttribute"/>
  68. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  69. public sealed class OnDisableAttribute : Attribute, IEdgeLifecycleAttribute
  70. {
  71. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Disable;
  72. }
  73. /// <summary>
  74. /// Indicates that the target method should be called when the game exits.
  75. /// </summary>
  76. /// <remarks>
  77. /// <para>
  78. /// This attribute is interchangable with <see cref="OnDisableAttribute"/>, and is treated identically.
  79. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  80. /// </para>
  81. /// <para>
  82. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  83. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.SingleStartInit"/>.
  84. /// </para>
  85. /// </remarks>
  86. /// <seealso cref="PluginAttribute"/>
  87. /// <seealso cref="OnDisableAttribute"/>
  88. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  89. public sealed class OnExitAttribute : Attribute, IEdgeLifecycleAttribute
  90. {
  91. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Disable;
  92. }
  93. }