GD0106.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. GD0106: The exported property is an explicit interface implementation
  2. =====================================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0106
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Non-breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. An explicit interface property implementation is annotated with the ``[Export]``
  14. attribute. Properties that implement an interface explicitly can't be exported.
  15. Rule description
  16. ----------------
  17. Godot doesn't allow exporting explicit interface property implementations.
  18. When an interface member is implemented explicitly, the member is hidden and
  19. consumers can't access them unless the type is converted to the interface first.
  20. Explicitly implemented members can also share the same name of other members in
  21. the type, so it could create naming conflicts with other exported members.
  22. .. code-block:: csharp
  23. public interface MyInterface
  24. {
  25. public int MyProperty { get; set; }
  26. }
  27. public class MyNode1 : Node, MyInterface
  28. {
  29. // The property can be exported because it implements the interface implicitly.
  30. [Export]
  31. public int MyProperty { get; set; }
  32. }
  33. public class MyNode2 : Node, MyInterface
  34. {
  35. // The property can't be exported because it implements the interface explicitly.
  36. [Export]
  37. int MyInterface.MyProperty { get; set; }
  38. }
  39. How to fix violations
  40. ---------------------
  41. To fix a violation of this rule, implement the interface implicitly or remove
  42. the ``[Export]`` attribute.
  43. When to suppress warnings
  44. -------------------------
  45. Do not suppress a warning from this rule. Explicit interface property implementations
  46. can't be exported so they will be ignored by Godot, resulting in runtime errors.