ReSharper 2017.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, ReSharper 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, ReSharper 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. ReSharper removes the partial keyword and adds a method body according to the preferences on the Code Editing | Member Generation page of ReSharper options:

Suboptimal codeAfter the quick-fix
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: 11 December 2017

See Also