JetBrains Rider 2022.2 Help

Code Inspection: Redundant 'partial' modifier on method declaration

Partial methods allow separating the method signature (declaration) from its implementation. A single declaration part of a partial method might indicate that the development was not completed.

A missing implementation part does not cause an error because in this case the method and all its calls are removed from the assembly at compile time. However, JetBrains Rider suggests that it is better to make such a method non-partial to eliminate unclear code.

If it is the declaration part that is missing, an error occurs. Again, JetBrains Rider suggests making such a method non-partial.

In the example below, the method ToCart() has only the declaration part, implementation parts of the method were not found in any part of the class. JetBrains Rider removes the partial keyword and adds a method body according to the preferences on the Editor | Member Generation page of JetBrains Rider settings Ctrl+Alt+S:

partial class Toy { public int Id { get; set; } partial void ToCart(); } partial class Toy { public bool CanBeep { get; set; } public bool CanJump { get; set; } }
partial class Toy { public int Id { get; set; } void ToCart() { throw new NotImplementedException(); } } partial class Toy { public bool CanBeep { get; set; } public bool CanJump { get; set; } }
Last modified: 08 March 2021