GD0202.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. GD0202: The parameter of the delegate signature of the signal is not supported
  2. ==============================================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0202
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Breaking - If the parameter type is changed
  9. Non-breaking - If the ``[Signal]`` attribute is removed
  10. **Enabled by default** Yes
  11. ==================================== ======================================
  12. Cause
  13. -----
  14. An unsupported type is specified for a parameter of a delegate annotated with
  15. the ``[Signal]`` attribute when a
  16. :ref:`Variant-compatible type <c_sharp_variant_compatible_types>` is expected.
  17. Rule description
  18. ----------------
  19. Every signal parameter must be Variant-compatible so it can be marshalled when
  20. emitting the signal and invoking the callbacks.
  21. .. code-block:: csharp
  22. class SomeType { }
  23. // SomeType is not a valid parameter type because it doesn't derive from GodotObject,
  24. // so it's not compatible with Variant.
  25. public void InvalidSignalEventHandler(SomeType someType);
  26. // System.Int32 is a valid type because it's compatible with Variant.
  27. public void ValidSignalEventHandler(int someInt);
  28. Take a look at the :ref:`C# signals <doc_c_sharp_signals>` documentation for more
  29. information about how to declare and use signals.
  30. How to fix violations
  31. ---------------------
  32. To fix a violation of this rule, change the parameter type to be Variant-compatible
  33. or remove the ``[Signal]`` attribute from the delegate. Note that removing the
  34. attribute will mean the signal is not registered.
  35. .. tip::
  36. If the signal doesn't need to interact with Godot, consider using
  37. `C# events <https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/>`_
  38. directly. Pure C# events allow you to use any C# type for its parameters.
  39. When to suppress warnings
  40. -------------------------
  41. Do not suppress a warning from this rule. Signal delegates with parameters that
  42. can't be marshalled will result in runtime errors when emitting the signal or
  43. invoking the callbacks.