GD0201.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. GD0201: The name of the delegate must end with 'EventHandler'
  2. =============================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0201
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. A delegate annotated with the ``[Signal]`` attribute has a name that doesn't
  14. end with 'EventHandler'.
  15. Rule description
  16. ----------------
  17. Godot source generators will generate C# events using the name of the delegate
  18. with the 'EventHandler' suffix removed. Adding the 'EventHandler' suffix to the
  19. name of delegates used in events is a `.NET naming convention <https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types>`_.
  20. Using a suffix for the delegate allows the generated event to use the name without
  21. the suffix avoiding a naming conflict.
  22. .. code-block:: csharp
  23. // This delegate is invalid since the name doesn't end with 'EventHandler'.
  24. [Signal]
  25. public void InvalidSignal();
  26. // This delegate is valid since the name ends with 'EventHandler'.
  27. [Signal]
  28. public void ValidSignalEventHandler();
  29. Take a look at the :ref:`C# signals <doc_c_sharp_signals>` documentation for more
  30. information about how to declare and use signals.
  31. How to fix violations
  32. ---------------------
  33. To fix a violation of this rule, add 'EventHandler' to the end of the delegate name.
  34. When to suppress warnings
  35. -------------------------
  36. Do not suppress a warning from this rule. Signal delegates without the suffix
  37. will be ignored by the source generator, so the signal won't be registered.